t-Shr commited on
Commit
697c956
Β·
verified Β·
1 Parent(s): 7ab7aef

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +32 -14
src/streamlit_app.py CHANGED
@@ -25,25 +25,43 @@ def predict(text, trust_score=0.5):
25
 
26
  return label, round(model_prob, 4), round(fused_score, 4), risk_score
27
 
28
- # Streamlit UI
29
- st.set_page_config(page_title="πŸ“© SMS Spam Classifier", layout="centered")
30
- st.title("πŸ“© Real-Time SMS Spam Classifier")
31
- st.markdown("Detect whether an SMS is **spam** or **ham**, with model confidence, fused score and risk score.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  # Text input
34
  sms_text = st.text_area("βœ‰οΈ Enter SMS Text:", height=150)
35
 
36
- # Trust score slider
37
- trust_score = st.slider("πŸ” Trust Score (user reliability)", 0.0, 1.0, 0.5, step=0.01)
38
-
39
- # Predict button
40
  if st.button("πŸ” Predict"):
41
  if sms_text.strip() == "":
42
- st.warning("Please enter some text to analyze.")
43
  else:
44
- label, confidence, fused_score, risk_score = predict(sms_text, trust_score)
 
 
 
 
 
45
 
46
- st.markdown(f"### βœ… Prediction: `{label}`")
47
- st.metric(label="πŸ“Š Model Confidence", value=f"{confidence:.2f}")
48
- st.metric(label="πŸ” Fused Score", value=f"{fused_score:.2f}")
49
- st.metric(label="⚠️ Risk Score", value=f"{risk_score}/100")
 
25
 
26
  return label, round(model_prob, 4), round(fused_score, 4), risk_score
27
 
28
+
29
+ # Fusion prediction function (trust_score fixed at 0.5)
30
+ def predict(text):
31
+ trust_score = 0.5
32
+ output = pipe(text)[0]
33
+ model_prob = output['score'] if output['label'] == 'LABEL_1' else 1 - output['score']
34
+
35
+ alpha = 0.7
36
+ fused = alpha * model_prob + (1 - alpha) * (1 - trust_score)
37
+ risk = int(round(fused * 100))
38
+ label = "SPAM" if fused >= 0.5 else "NOT SPAM"
39
+ return label, round(model_prob, 4), round(fused, 4), risk
40
+
41
+ # UI config
42
+ st.set_page_config(page_title="SMS Spam Detector", layout="centered")
43
+ st.title("πŸ“© Real-Time SMS Spam Detector")
44
+
45
+ st.markdown("Enter an SMS message to check if it's likely spam. The system will show you:")
46
+ st.markdown("- πŸ“Š **Model Confidence**")
47
+ st.markdown("- πŸ” **Fused Score** (combined model + trust logic)")
48
+ st.markdown("- ⚠️ **Risk Score** out of 100")
49
 
50
  # Text input
51
  sms_text = st.text_area("βœ‰οΈ Enter SMS Text:", height=150)
52
 
53
+ # Predict
 
 
 
54
  if st.button("πŸ” Predict"):
55
  if sms_text.strip() == "":
56
+ st.warning("Please enter some text.")
57
  else:
58
+ label, confidence, fused_score, risk_score = predict(sms_text)
59
+
60
+ if label == "SPAM":
61
+ st.markdown(f"### πŸŸ₯ Prediction: **`SPAM`**")
62
+ else:
63
+ st.markdown(f"### 🟩 Prediction: **`NOT SPAM`**")
64
 
65
+ st.metric("πŸ“Š Model Confidence", f"{confidence:.2f}")
66
+ st.metric("πŸ” Fused Score", f"{fused_score:.2f}")
67
+ st.metric("⚠️ Risk Score", f"{risk_score}/100")