import os import joblib import streamlit as st st.set_page_config(page_title="Fake News Detector", page_icon="📰", layout="centered") st.title("📰 Fake News Detector") st.write("Paste a news text (or headline) and the model will predict **FAKE** or **REAL**.") MODEL_PATH = os.path.join("src/fake_news_svc_tfidf.pkl") @st.cache_resource def load_model(): if not os.path.exists(MODEL_PATH): raise FileNotFoundError( f"Model not found at: {MODEL_PATH}\n" "Make sure the file is in the repo under models/." ) return joblib.load(MODEL_PATH) model = load_model() text_input = st.text_area("News text / headline:", height=200, placeholder="Paste text here...") col1, col2 = st.columns([1, 1]) with col1: predict_btn = st.button("Predict", type="primary") with col2: clear_btn = st.button("Clear") if clear_btn: st.rerun() if predict_btn: if not text_input.strip(): st.warning("Please enter some text first.") else: pred = model.predict([text_input])[0] # 0/1 label = "REAL ✅" if pred == 1 else "FAKE 🚨" st.subheader("Prediction") st.success(label) # Optional: show a score (LinearSVC has decision_function) try: score = float(model.decision_function([text_input])[0]) st.caption(f"Decision score (higher → REAL, lower → FAKE): {score:.4f}") except Exception: pass st.divider() st.caption("Model: TF-IDF + Linear SVC (saved with joblib).")