import streamlit as st import joblib import os # ====================== # LOAD MODEL + VECTORIZER # ====================== BASE_DIR = os.path.dirname(os.path.abspath(__file__)) model, vectorizer = joblib.load(os.path.join(BASE_DIR, "model.pkl")) # ====================== # PAGE CONFIG # ====================== st.set_page_config( page_title="Fake News Detection", page_icon="📰", layout="centered" ) st.title("📰 Fake News Detection") st.write("Paste a news article to check whether it is Fake or Real.") news = st.text_area("Enter news text") # ====================== # PREDICTION # ====================== if st.button("Predict"): news_vec = vectorizer.transform([news]) prediction = model.predict(news_vec)[0] proba = model.predict_proba(news_vec)[0] confidence = proba.max() if prediction == "REAL": st.success(f"Real News ✅ ({confidence:.2%})") else: st.error(f"Fake News ❌ ({confidence:.2%})") if confidence < 0.65: st.warning("Low confidence prediction ⚠️")