Sanjayraju30 commited on
Commit
b7302da
·
verified ·
1 Parent(s): 463c018

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load fake news classifier
5
+ classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news", return_all_scores=True)
6
+
7
+ def detect_fake_news(text):
8
+ results = classifier(text)[0]
9
+ results = sorted(results, key=lambda x: x['score'], reverse=True)
10
+
11
+ label = results[0]['label']
12
+ confidence = results[0]['score']
13
+
14
+ explanation = f"This article is classified as **{label.upper()}** with a confidence of **{confidence*100:.2f}%**.\n\n"
15
+ explanation += "### Full Scores:\n"
16
+ for r in results:
17
+ explanation += f"- {r['label']}: {r['score']*100:.2f}%\n"
18
+
19
+ return explanation
20
+
21
+ # Gradio Interface
22
+ demo = gr.Interface(
23
+ fn=detect_fake_news,
24
+ inputs=gr.Textbox(lines=12, placeholder="Paste your news article here...", label="📰 News Article"),
25
+ outputs=gr.Markdown(label="🧠 Fake News Analysis"),
26
+ title="🕵️‍♀️ Fake News Detector",
27
+ description="Paste a news article. This app will classify it as FAKE or REAL using a BERT-based model."
28
+ )
29
+
30
+ demo.launch()