|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
from newspaper import Article |
|
|
|
|
|
|
|
|
model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection") |
|
|
|
|
|
def analyze(input_text, input_type): |
|
|
|
|
|
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() |
|
|
|