Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Text input
|
| 34 |
sms_text = st.text_area("βοΈ Enter SMS Text:", height=150)
|
| 35 |
|
| 36 |
-
#
|
| 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
|
| 43 |
else:
|
| 44 |
-
label, confidence, fused_score, risk_score = predict(sms_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
st.
|
| 47 |
-
st.metric(
|
| 48 |
-
st.metric(
|
| 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")
|
|
|