Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
classifier = pipeline("text-classification", model="
|
6 |
|
7 |
def detect_fake_news(text):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
label = results[0]['label']
|
12 |
-
confidence = results[0]['score']
|
13 |
-
|
14 |
-
explanation = f"This article is classified as **{label.upper()}** with a confidence of **{confidence*100:.2f}%**.\n\n"
|
15 |
-
explanation += "### Full Scores:\n"
|
16 |
-
for r in results:
|
17 |
-
explanation += f"- {r['label']}: {r['score']*100:.2f}%\n"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
return explanation
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
title="🕵️♀️ Fake News Detector",
|
27 |
-
description="Paste a news article. This app will classify it as FAKE or REAL using a BERT-based model."
|
28 |
-
)
|
29 |
|
30 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Use a valid public model
|
5 |
+
classifier = pipeline("text-classification", model="michiyasunaga/BERT-fake-news-detection")
|
6 |
|
7 |
def detect_fake_news(text):
|
8 |
+
result = classifier(text)[0]
|
9 |
+
label = result['label']
|
10 |
+
score = result['score']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
explanation = (
|
13 |
+
f"The model predicts this news is **{label}** "
|
14 |
+
f"with a confidence of **{score:.2f}**.\n\n"
|
15 |
+
"🧠 This is based on BERT fine-tuned on a fake news dataset."
|
16 |
+
)
|
17 |
return explanation
|
18 |
|
19 |
+
demo = gr.Interface(fn=detect_fake_news,
|
20 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
|
21 |
+
outputs="markdown",
|
22 |
+
title="🕵️ Fake News Detector",
|
23 |
+
description="An NLP app that predicts whether a news article is fake or real using BERT.")
|
|
|
|
|
|
|
24 |
|
25 |
demo.launch()
|