File size: 1,350 Bytes
f063d89
c460319
c2df4c7
 
eb129d7
f382f8d
307d5cd
 
 
12b33d8
eb129d7
f063d89
 
eb129d7
f063d89
 
e637464
307d5cd
f063d89
eb129d7
 
 
 
 
12b33d8
697c956
 
eb129d7
f063d89
 
eb129d7
 
 
 
 
 
f063d89
eb129d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import streamlit as st
from transformers import pipeline

# Redirect cache
cache_dir = os.path.join(os.getcwd(), "/tmp/hf_cache")
os.makedirs(cache_dir, exist_ok=True)
os.environ["TRANSFORMERS_CACHE"] = cache_dir
os.environ["HF_HOME"] = cache_dir

# Load model (ensure it's public or token is handled securely)
pipe = pipeline(
    "text-classification",
    model="t-Shr/SPAM_OR_HAM_SMS"  # πŸ”’ make sure it's public or token is handled
)

def predict(text):
    trust_score = 0.5
    output = pipe(text)[0]
    prob = output['score'] if output['label'] == 'LABEL_1' else 1 - output['score']
    fused = 0.7 * prob + 0.3 * (1 - trust_score)
    risk = int(round(fused * 100))
    label = "SPAM" if fused >= 0.5 else "NOT SPAM"
    return label, round(prob, 4), round(fused, 4), risk

st.set_page_config(page_title="SMS Spam Detector", layout="centered")
st.title("πŸ“© Real-Time SMS Spam Detector")
sms = st.text_area("βœ‰οΈ Enter SMS:", height=150)

if st.button("πŸ” Predict"):
    if sms.strip():
        label, prob, fused, risk = predict(sms)
        st.markdown(f"### {'πŸŸ₯' if label == 'SPAM' else '🟩'} Prediction: `{label}`")
        st.metric("Confidence", f"{prob:.2f}")
        st.metric("Fused Score", f"{fused:.2f}")
        st.metric("Risk Score", f"{risk}/100")
    else:
        st.warning("Please enter SMS text.")