Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Use a
|
5 |
-
classifier = pipeline("text-classification", model="
|
6 |
|
|
|
7 |
def detect_fake_news(text):
|
8 |
result = classifier(text)[0]
|
9 |
-
label = result[
|
10 |
-
score = result[
|
11 |
-
|
12 |
-
|
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 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# ✅ Use a working fake news detection model
|
5 |
+
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
6 |
|
7 |
+
# 💡 Function to classify news
|
8 |
def detect_fake_news(text):
|
9 |
result = classifier(text)[0]
|
10 |
+
label = result["label"]
|
11 |
+
score = result["score"]
|
12 |
+
explanation = "🟢 This looks like real news." if label == "REAL" else "🔴 This might be fake news."
|
13 |
+
return f"Prediction: {label}\nConfidence: {score:.2f}\n{explanation}"
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# 🎛️ Gradio UI
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=detect_fake_news,
|
18 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
|
19 |
+
outputs="text",
|
20 |
+
title="📰 Fake News Detector",
|
21 |
+
description="Detect whether a news article is real or fake using a fine-tuned BERT model."
|
22 |
+
)
|
23 |
|
24 |
+
iface.launch()
|