Sanjayraju30 commited on
Commit
2b5ac81
·
verified ·
1 Parent(s): 37f198d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -1,25 +1,24 @@
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()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Use a working fake news detection model
5
+ classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
6
 
7
+ # 💡 Function to classify news
8
  def detect_fake_news(text):
9
  result = classifier(text)[0]
10
+ label = result["label"]
11
+ score = result["score"]
12
+ explanation = "🟢 This looks like real news." if label == "REAL" else "🔴 This might be fake news."
13
+ return f"Prediction: {label}\nConfidence: {score:.2f}\n{explanation}"
 
 
 
 
 
14
 
15
+ # 🎛️ Gradio UI
16
+ iface = gr.Interface(
17
+ fn=detect_fake_news,
18
+ inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
19
+ outputs="text",
20
+ title="📰 Fake News Detector",
21
+ description="Detect whether a news article is real or fake using a fine-tuned BERT model."
22
+ )
23
 
24
+ iface.launch()