import streamlit as st import joblib import re from related_news import fetch_related_articles # Load model and vectorizer model = joblib.load("model.pkl") vectorizer = joblib.load("vectorizer.pkl") # ๐งผ Text cleaning function def clean_text(text): text = re.sub(r"http\S+", "", text) text = re.sub(r"[^a-zA-Z\s]", "", text) text = text.lower() return text # ๐ Page setup st.set_page_config( page_title="TruthRadar ๐ง ", page_icon="๐ฐ๏ธ", layout="centered", initial_sidebar_state="auto" ) # ๐จ Custom styles for light theme st.markdown(""" """, unsafe_allow_html=True) # ๐ฐ๏ธ Header st.markdown("
Detect fake news in a flash โ headlines or full articles ๐
", unsafe_allow_html=True) st.markdown("---") st.markdown("Currently optimised for US-based news articles.
", unsafe_allow_html=True) #input st.markdown("", unsafe_allow_html=True) user_input = st.text_area("", height=200) # ๐ Analyze button if st.button("๐ Analyze"): if not user_input.strip(): st.warning("Bruhhh paste *something* to analyze ๐ ") else: with st.spinner("๐ง Scanning for truth..."): try: cleaned = clean_text(user_input) transformed = vectorizer.transform([cleaned]) prediction = model.predict(transformed)[0] proba = model.predict_proba(transformed)[0] confidence = max(proba) * 100 label = prediction.upper() articles = fetch_related_articles(user_input) # โจ Show prediction result using markdown for HTML formatting if label == "REAL": st.markdown("Made with ๐ป by Sai Srikar โข TruthRadar AI
", unsafe_allow_html=True)