Sanjayraju30 commited on
Commit
8b6f51c
Β·
verified Β·
1 Parent(s): 34d64bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -4,13 +4,18 @@ from transformers import pipeline
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(
@@ -18,7 +23,8 @@ iface = gr.Interface(
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()
 
 
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 and give explanation
8
  def detect_fake_news(text):
9
  result = classifier(text)[0]
10
  label = result["label"]
11
  score = result["score"]
12
+
13
+ if label == "FAKE":
14
+ explanation = "πŸ”΄ This might be fake news.\n\n🧠 Reason: The model detected signs of misinformation, such as exaggerated claims, lack of credible sources, or emotionally charged language."
15
+ else:
16
+ explanation = "🟒 This looks like real news. It likely follows factual reporting patterns."
17
+
18
+ return f"Prediction: {label}\nConfidence: {score:.2f}\n\n{explanation}"
19
 
20
  # πŸŽ›οΈ Gradio UI
21
  iface = gr.Interface(
 
23
  inputs=gr.Textbox(lines=10, placeholder="Paste your news article here..."),
24
  outputs="text",
25
  title="πŸ“° Fake News Detector",
26
+ description="Detect whether a news article is real or fake using a fine-tuned BERT model. Includes explanation for fake news."
27
  )
28
 
29
  iface.launch()
30
+