Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import pickle
|
|
| 3 |
import re
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
|
| 7 |
# Streamlit page configuration
|
| 8 |
st.set_page_config(page_title="Stack Overflow Tags Predictor", layout="centered")
|
| 9 |
|
|
@@ -36,9 +35,6 @@ st.markdown("Enter a question's *title* and *description*, and this app will sug
|
|
| 36 |
title = st.text_input("π Question Title")
|
| 37 |
body = st.text_area("π Question Description", height=200)
|
| 38 |
|
| 39 |
-
# Optional: Add a threshold slider
|
| 40 |
-
#threshold = st.slider("π§ Tag Confidence Threshold", min_value=0.1, max_value=0.9, value=0.3, step=0.05)
|
| 41 |
-
|
| 42 |
# Prediction Button
|
| 43 |
if st.button("π Predict Tags"):
|
| 44 |
if not title.strip() or not body.strip():
|
|
@@ -48,18 +44,17 @@ if st.button("π Predict Tags"):
|
|
| 48 |
X_input = vectorizer.transform([input_text])
|
| 49 |
|
| 50 |
try:
|
| 51 |
-
# Use predict_proba and apply threshold
|
| 52 |
-
y_prob = model.predict_proba(X_input)
|
| 53 |
-
y_pred = (y_prob >= threshold).astype(int)
|
| 54 |
-
except AttributeError:
|
| 55 |
-
st.warning("β Model does not support `predict_proba`. Using default `predict` method.")
|
| 56 |
y_pred = model.predict(X_input)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
|
|
|
| 3 |
import re
|
| 4 |
import numpy as np
|
| 5 |
|
|
|
|
| 6 |
# Streamlit page configuration
|
| 7 |
st.set_page_config(page_title="Stack Overflow Tags Predictor", layout="centered")
|
| 8 |
|
|
|
|
| 35 |
title = st.text_input("π Question Title")
|
| 36 |
body = st.text_area("π Question Description", height=200)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
# Prediction Button
|
| 39 |
if st.button("π Predict Tags"):
|
| 40 |
if not title.strip() or not body.strip():
|
|
|
|
| 44 |
X_input = vectorizer.transform([input_text])
|
| 45 |
|
| 46 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
y_pred = model.predict(X_input)
|
| 48 |
+
except Exception as e:
|
| 49 |
+
st.error(f"β Prediction failed: {e}")
|
| 50 |
+
y_pred = None
|
| 51 |
+
|
| 52 |
+
if y_pred is not None:
|
| 53 |
+
predicted_tags = mlb.inverse_transform(y_pred)
|
| 54 |
+
|
| 55 |
+
if predicted_tags and predicted_tags[0]:
|
| 56 |
+
st.success("β
Predicted Tags:")
|
| 57 |
+
st.write(", ".join(predicted_tags[0]))
|
| 58 |
+
else:
|
| 59 |
+
st.info("π€ No tags predicted. Try refining your question.")
|
| 60 |
|