Team Ai
Apppublic

sree4411/Stack_overflow

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py56 linesDownload Raw Back to root
1import pickle2import streamlit as st3import os4import numpy as np5 6# ๐Ÿ’ก Define the custom tokenizer exactly as used during training7def custom_tokenizer(text):8    # Modify this function to match your original tokenizer logic9    return text.lower().split()10 11 12 13# ๐Ÿ”ƒ Load model files14try:15    with open("tfidf.pkl", "rb") as f:16        vectorizer = pickle.load(f)17 18    with open("model (3).pkl", "rb") as f:19        model = pickle.load(f)20 21    with open("mlb (1).pkl", "rb") as f:22        mlb = pickle.load(f)23 24except Exception as e:25    st.error(f"โŒ Error loading model files: {str(e)}")26    st.stop()27 28# ๐Ÿง  Prediction function29def predict_tags(title, description):30    try:31        if not title.strip() or not description.strip():32            return "โš ๏ธ Please enter both title and description."33 34        input_text = title + " " + description35        input_vector = vectorizer.transform([input_text])36        prediction = model.predict(input_vector)37        predicted_tags = mlb.inverse_transform(prediction)38        st.write(predicted_tags)39        if predicted_tags and predicted_tags[0]:40            return "โœ… Predicted Tags: " + ", ".join(predicted_tags[0])41        else:42            return "โ„น๏ธ No tags predicted. Try refining your question."43 44    except Exception as e:45        return f"โŒ Error during prediction: {str(e)}"46 47# ๐Ÿš€ Streamlit UI48st.title("๐Ÿ”– Stack Overflow Tags Predictor")49st.markdown("Enter a question title and description to predict relevant tags.")50 51title = st.text_input("๐Ÿ“Œ Enter Question Title")52description = st.text_area("๐Ÿ“ Enter Question Description", height=150)53 54if st.button("Predict Tags"):55    result = predict_tags(title, description)56    st.markdown(result)