Spaces:
Sleeping
Sleeping
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() | |