File size: 1,712 Bytes
6bd12f9 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
from transformers import pipeline
from newspaper import Article
# Load the model
model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
def analyze(input_text, input_type):
# Auto-detect if input is URL or text
if input_type == "Auto Detect":
if input_text.startswith("http://") or input_text.startswith("https://"):
input_type = "URL"
else:
input_type = "Text"
if input_type == "URL":
try:
article = Article(input_text)
article.download()
article.parse()
text = article.text
except Exception as e:
return f"❌ Failed to extract article: {e}", 0
else:
text = input_text
if not text:
return "❌ No text provided", 0
try:
result = model(text)[0]
label = result["label"]
score = result["score"]
verdict = "Authentic" if label == "REAL" else "Possibly Misinformation"
authenticity_score = round(score * 100, 2)
return verdict, authenticity_score
except Exception as e:
return f"❌ Model inference failed: {e}", 0
interface = gr.Interface(
fn=analyze,
inputs=[
gr.Textbox(lines=6, label="Paste article text or URL here"),
gr.Radio(["Auto Detect", "Text", "URL"], label="Input Type", value="Auto Detect")
],
outputs=[
gr.Textbox(label="Verdict"),
gr.Number(label="Authenticity Score (%)")
],
title="Misinformation Detection Dashboard",
description="Enter article text or a URL to detect whether the content is authentic or possibly misinformation."
)
interface.launch()
|