Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,42 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
outputs="text",
|
| 44 |
-
title="🔖 Stack Overflow Tags Predictor",
|
| 45 |
-
description="Enter a question's title and description to get tag suggestions."
|
| 46 |
-
)
|
| 47 |
-
iface.launch()
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
# Load models using pickle
|
| 7 |
+
with open("tfidf_vectorizer(1).pkl", "rb") as f:
|
| 8 |
+
vectorizer = pickle.load(f)
|
| 9 |
+
|
| 10 |
+
with open("model(1).pkl", "rb") as f:
|
| 11 |
+
model = pickle.load(f)
|
| 12 |
+
|
| 13 |
+
with open("mlb.pkl", "rb") as f:
|
| 14 |
+
mlb = pickle.load(f)
|
| 15 |
+
|
| 16 |
+
# Streamlit App UI
|
| 17 |
+
st.set_page_config(page_title="🔖 Stack Overflow Tags Predictor", layout="centered")
|
| 18 |
+
|
| 19 |
+
st.title("🔖 Stack Overflow Tags Predictor")
|
| 20 |
+
st.write("Enter the question's title and description to get suggested tags.")
|
| 21 |
+
|
| 22 |
+
# Input fields
|
| 23 |
+
title = st.text_input("Enter Question Title:")
|
| 24 |
+
description = st.text_area("Enter Question Description:")
|
| 25 |
+
|
| 26 |
+
# Prediction logic
|
| 27 |
+
if st.button("Predict Tags"):
|
| 28 |
+
if not title.strip() or not description.strip():
|
| 29 |
+
st.warning("⚠️ Please enter both title and description.")
|
| 30 |
+
else:
|
| 31 |
+
try:
|
| 32 |
+
input_text = title + " " + description
|
| 33 |
+
input_vector = vectorizer.transform([input_text])
|
| 34 |
+
prediction = model.predict(input_vector)
|
| 35 |
+
predicted_tags = mlb.inverse_transform(prediction)
|
| 36 |
+
|
| 37 |
+
if predicted_tags and predicted_tags[0]:
|
| 38 |
+
st.success("✅ Predicted Tags: " + ", ".join(predicted_tags[0]))
|
| 39 |
+
else:
|
| 40 |
+
st.info("ℹ️ No tags predicted. Try refining your question.")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"❌ Error: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|