File size: 1,087 Bytes
b7302da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
from transformers import pipeline

# Load fake news classifier
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news", return_all_scores=True)

def detect_fake_news(text):
    results = classifier(text)[0]
    results = sorted(results, key=lambda x: x['score'], reverse=True)

    label = results[0]['label']
    confidence = results[0]['score']

    explanation = f"This article is classified as **{label.upper()}** with a confidence of **{confidence*100:.2f}%**.\n\n"
    explanation += "### Full Scores:\n"
    for r in results:
        explanation += f"- {r['label']}: {r['score']*100:.2f}%\n"
    
    return explanation

# Gradio Interface
demo = gr.Interface(
    fn=detect_fake_news,
    inputs=gr.Textbox(lines=12, placeholder="Paste your news article here...", label="📰 News Article"),
    outputs=gr.Markdown(label="🧠 Fake News Analysis"),
    title="🕵️‍♀️ Fake News Detector",
    description="Paste a news article. This app will classify it as FAKE or REAL using a BERT-based model."
)

demo.launch()