Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,18 @@ from transformers import pipeline
|
|
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 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# ποΈ Gradio UI
|
16 |
iface = gr.Interface(
|
@@ -18,7 +23,8 @@ iface = gr.Interface(
|
|
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()
|
|
|
|
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 and give explanation
|
8 |
def detect_fake_news(text):
|
9 |
result = classifier(text)[0]
|
10 |
label = result["label"]
|
11 |
score = result["score"]
|
12 |
+
|
13 |
+
if label == "FAKE":
|
14 |
+
explanation = "π΄ This might be fake news.\n\nπ§ Reason: The model detected signs of misinformation, such as exaggerated claims, lack of credible sources, or emotionally charged language."
|
15 |
+
else:
|
16 |
+
explanation = "π’ This looks like real news. It likely follows factual reporting patterns."
|
17 |
+
|
18 |
+
return f"Prediction: {label}\nConfidence: {score:.2f}\n\n{explanation}"
|
19 |
|
20 |
# ποΈ Gradio UI
|
21 |
iface = gr.Interface(
|
|
|
23 |
inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
|
24 |
outputs="text",
|
25 |
title="π° Fake News Detector",
|
26 |
+
description="Detect whether a news article is real or fake using a fine-tuned BERT model. Includes explanation for fake news."
|
27 |
)
|
28 |
|
29 |
iface.launch()
|
30 |
+
|