File size: 1,192 Bytes
0ac6a38
 
 
 
 
 
 
 
ededeea
0ac6a38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
from pathlib import Path

# Set page config
st.set_page_config(page_title="Fake News Detector")

# Use local model directory relative to app.py
MODEL_DIR = Path("ragkasi/bert-fake-news")

@st.cache_resource
def load_pipeline():
    tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
    model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
    return pipeline("text-classification", model=model, tokenizer=tokenizer)

classifier = load_pipeline()

# UI
st.title("Fake News Detector")
st.markdown("Enter a news **headline** or **statement**, and this app will predict if it's **real** or **fake**.")

news_input = st.text_area("News Text", height=150)

if st.button("Check News"):
    if news_input.strip():
        result = classifier(news_input)[0]
        label = result["label"]
        score = result["score"]

        if label == "LABEL_1":
            st.error(f"Likely Fake News (Confidence: `{score:.2f}`)")
        else:
            st.success(f"Likely Real News (Confidence: `{score:.2f}`)")
    else:
        st.warning("Please enter a news statement.")