Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
st.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
if label == "LABEL_1":
|
32 |
-
st.error(f"
|
33 |
-
else:
|
34 |
-
st.success(f"
|
35 |
-
else:
|
36 |
-
st.warning("
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
# Set page config
|
6 |
+
st.set_page_config(page_title="Fake News Detector")
|
7 |
+
|
8 |
+
# Use local model directory relative to app.py
|
9 |
+
MODEL_DIR = Path("models/bert-fake-news")
|
10 |
+
|
11 |
+
@st.cache_resource
|
12 |
+
def load_pipeline():
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
|
14 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
|
15 |
+
return pipeline("text-classification", model=model, tokenizer=tokenizer)
|
16 |
+
|
17 |
+
classifier = load_pipeline()
|
18 |
+
|
19 |
+
# UI
|
20 |
+
st.title("Fake News Detector")
|
21 |
+
st.markdown("Enter a news **headline** or **statement**, and this app will predict if it's **real** or **fake**.")
|
22 |
+
|
23 |
+
news_input = st.text_area("News Text", height=150)
|
24 |
+
|
25 |
+
if st.button("Check News"):
|
26 |
+
if news_input.strip():
|
27 |
+
result = classifier(news_input)[0]
|
28 |
+
label = result["label"]
|
29 |
+
score = result["score"]
|
30 |
+
|
31 |
+
if label == "LABEL_1":
|
32 |
+
st.error(f"Likely Fake News (Confidence: `{score:.2f}`)")
|
33 |
+
else:
|
34 |
+
st.success(f"Likely Real News (Confidence: `{score:.2f}`)")
|
35 |
+
else:
|
36 |
+
st.warning("Please enter a news statement.")
|