Spaces:
Runtime error
Runtime error
Download src/streamlit_app.py from BeyzaTopbas/SMS-Spam-Detection: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/BeyzaTopbas/SMS-Spam-Detection/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/BeyzaTopbas/SMS-Spam-Detection/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/BeyzaTopbas/SMS-Spam-Detection/resolve/main/src/streamlit_app.py
1.01 kB
| import streamlit as st | |
| import joblib | |
| import os | |
| # ====================== | |
| # LOAD MODEL | |
| # ====================== | |
| BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| model = joblib.load(os.path.join(BASE_DIR, "model.pkl")) | |
| vectorizer = joblib.load(os.path.join(BASE_DIR, "vectorizer.pkl")) | |
| # ====================== | |
| # PAGE | |
| # ====================== | |
| st.set_page_config(page_title="SMS Spam Detection", page_icon="📩") | |
| st.title("📩 SMS Spam Detection") | |
| st.write("Classify SMS messages as Spam or Ham") | |
| # ====================== | |
| # INPUT | |
| # ====================== | |
| message = st.text_area("Enter your message") | |
| # ====================== | |
| # PREDICT | |
| # ====================== | |
| if st.button("Predict"): | |
| message_vec = vectorizer.transform([message]) | |
| prediction = model.predict(message_vec)[0] | |
| proba = model.predict_proba(message_vec) | |
| confidence = proba.max() | |
| if prediction == "spam": | |
| st.error(f"🚫 Spam ({confidence:.2%})") | |
| else: | |
| st.success(f"✅ Ham ({confidence:.2%})") |