Ramyamaheswari commited on
Commit
c809b3e
Β·
verified Β·
1 Parent(s): 9fa7fcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
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
- predicted_tags = mlb.inverse_transform(y_pred)
59
-
60
- if predicted_tags and predicted_tags[0]:
61
- st.success("βœ… Predicted Tags:")
62
- st.write(", ".join(predicted_tags[0]))
63
- else:
64
- st.info("πŸ€” No tags predicted. Try refining your question or lowering the threshold.")
 
 
 
 
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