Sanjayraju30 commited on
Commit
e88771b
·
verified ·
1 Parent(s): 6f8954b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -1,30 +1,25 @@
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()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Use a valid public model
5
+ classifier = pipeline("text-classification", model="michiyasunaga/BERT-fake-news-detection")
6
 
7
  def detect_fake_news(text):
8
+ result = classifier(text)[0]
9
+ label = result['label']
10
+ score = result['score']
 
 
 
 
 
 
 
11
 
12
+ explanation = (
13
+ f"The model predicts this news is **{label}** "
14
+ f"with a confidence of **{score:.2f}**.\n\n"
15
+ "🧠 This is based on BERT fine-tuned on a fake news dataset."
16
+ )
17
  return explanation
18
 
19
+ demo = gr.Interface(fn=detect_fake_news,
20
+ inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
21
+ outputs="markdown",
22
+ title="🕵️ Fake News Detector",
23
+ description="An NLP app that predicts whether a news article is fake or real using BERT.")
 
 
 
24
 
25
  demo.launch()