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