Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,31 +3,38 @@ import joblib
|
|
| 3 |
import re
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model = joblib.load("tag_predictor_model.pkl")
|
| 8 |
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
| 9 |
mlb = joblib.load("label_binarizer.pkl")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
def clean_text(text):
|
| 13 |
soup = BeautifulSoup(text, "html.parser").get_text()
|
| 14 |
text = re.sub(r'[^a-zA-Z\s]', '', text.lower())
|
| 15 |
return " ".join([word for word in text.split() if len(word) > 2])
|
| 16 |
|
| 17 |
-
#
|
| 18 |
st.title("π€ Stack Overflow Tag Predictor")
|
| 19 |
-
st.write("Enter a Stack Overflow question to predict relevant tags.")
|
| 20 |
|
| 21 |
-
# Input
|
| 22 |
-
title = st.text_input("
|
| 23 |
-
body = st.text_area("
|
| 24 |
|
|
|
|
| 25 |
if st.button("Predict Tags"):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
st.subheader("π Predicted Tags:")
|
| 33 |
-
st.write(", ".join(predicted_tags[0]) if predicted_tags else "No tags predicted.")
|
|
|
|
| 3 |
import re
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
|
| 6 |
+
# Load models
|
| 7 |
model = joblib.load("tag_predictor_model.pkl")
|
| 8 |
vectorizer = joblib.load("tfidf_vectorizer.pkl")
|
| 9 |
mlb = joblib.load("label_binarizer.pkl")
|
| 10 |
|
| 11 |
+
# Text cleaning function
|
| 12 |
def clean_text(text):
|
| 13 |
soup = BeautifulSoup(text, "html.parser").get_text()
|
| 14 |
text = re.sub(r'[^a-zA-Z\s]', '', text.lower())
|
| 15 |
return " ".join([word for word in text.split() if len(word) > 2])
|
| 16 |
|
| 17 |
+
# App layout
|
| 18 |
st.title("π€ Stack Overflow Tag Predictor")
|
| 19 |
+
st.write("Enter a Stack Overflow question (title + body) to predict relevant tags.")
|
| 20 |
|
| 21 |
+
# Input fields
|
| 22 |
+
title = st.text_input("π Question Title")
|
| 23 |
+
body = st.text_area("π Question Body")
|
| 24 |
|
| 25 |
+
# Predict
|
| 26 |
if st.button("Predict Tags"):
|
| 27 |
+
if not title and not body:
|
| 28 |
+
st.warning("Please enter either a title or body.")
|
| 29 |
+
else:
|
| 30 |
+
with st.spinner("Predicting..."):
|
| 31 |
+
input_text = title + " " + body
|
| 32 |
+
cleaned = clean_text(input_text)
|
| 33 |
+
vectorized = vectorizer.transform([cleaned])
|
| 34 |
+
probas = model.predict_proba(vectorized)
|
| 35 |
+
prediction = (probas >= 0.3).astype(int)
|
| 36 |
+
predicted_tags = mlb.inverse_transform(prediction)
|
| 37 |
+
|
| 38 |
+
st.subheader("π Predicted Tags:")
|
| 39 |
+
st.write(", ".join(predicted_tags[0]) if predicted_tags[0] else "No tags predicted.")
|
| 40 |
|
|
|
|
|
|