Sanjayraju30 commited on
Commit
174d12c
Β·
verified Β·
1 Parent(s): 8b6f51c

Update app.py

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