Spaces:
Sleeping
Sleeping
| 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 β οΈ") |