Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# 1. LOAD A REAL FAKE NEWS MODEL
|
| 5 |
+
# This model is specifically trained to detect fake news, not just sentiment.
|
| 6 |
+
model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
| 7 |
+
|
| 8 |
+
def detect_fake_news(text):
|
| 9 |
+
result = model(text)[0]
|
| 10 |
+
label = result['label']
|
| 11 |
+
|
| 12 |
+
# LABEL_0 usually means Fake, LABEL_1 means Real for this specific model
|
| 13 |
+
if label == "LABEL_0":
|
| 14 |
+
return "β Fake News"
|
| 15 |
+
else:
|
| 16 |
+
return "β
Real News"
|
| 17 |
+
|
| 18 |
+
# 2. IMPROVED UI (Using gr.Blocks for better layout)
|
| 19 |
+
# We use 'theme=gr.themes.Soft()' for a modern look
|
| 20 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 21 |
+
|
| 22 |
+
# Header
|
| 23 |
+
gr.Markdown("# π° AI Fake News Detector")
|
| 24 |
+
gr.Markdown("Paste a news headline below to see if the AI thinks it is real or fake.")
|
| 25 |
+
|
| 26 |
+
# Two columns: Input on the left, Output on the right
|
| 27 |
+
with gr.Row():
|
| 28 |
+
input_text = gr.Textbox(lines=5, placeholder="Paste news text here...", label="News Article")
|
| 29 |
+
output_text = gr.Textbox(label="Prediction Result")
|
| 30 |
+
|
| 31 |
+
# A big colored button
|
| 32 |
+
submit_btn = gr.Button("π Check Veracity", variant="primary")
|
| 33 |
+
|
| 34 |
+
# Connect the button to the function
|
| 35 |
+
submit_btn.click(fn=detect_fake_news, inputs=input_text, outputs=output_text)
|
| 36 |
+
|
| 37 |
+
# Launch the app
|
| 38 |
+
demo.launch()
|