Nuhin23 commited on
Commit
ff2b0e6
·
verified ·
1 Parent(s): e4ecbf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -5
app.py CHANGED
@@ -1,7 +1,7 @@
1
- import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load model (Bangla + English supported)
5
  classifier = pipeline(
6
  "text-classification",
7
  model="mrm8488/bert-tiny-finetuned-fake-news-detection"
@@ -15,8 +15,8 @@ def predict_news(text):
15
  label = result["label"]
16
  confidence = round(result["score"] * 100, 2)
17
 
18
- # Label mapping
19
- if label.upper() == "FAKE":
20
  display_label = "Fake"
21
  color = "red"
22
  else:
@@ -62,7 +62,83 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
62
  confidence_bar = gr.Slider(
63
  minimum=0,
64
  maximum=100,
65
- label="Accuracy Percentage",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  interactive=False
67
  )
68
 
 
1
+ import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load model
5
  classifier = pipeline(
6
  "text-classification",
7
  model="mrm8488/bert-tiny-finetuned-fake-news-detection"
 
15
  label = result["label"]
16
  confidence = round(result["score"] * 100, 2)
17
 
18
+ # Correct label mapping
19
+ if label == "LABEL_0":
20
  display_label = "Fake"
21
  color = "red"
22
  else:
 
62
  confidence_bar = gr.Slider(
63
  minimum=0,
64
  maximum=100,
65
+ label="Confidence Percentage",
66
+ interactive=False
67
+ )
68
+
69
+ submit_btn.click(
70
+ fn=predict_news,
71
+ inputs=news_input,
72
+ outputs=[prediction_output, confidence_bar]
73
+ )
74
+
75
+ demo.launch()
76
+
77
+ import gradio as gr
78
+ from transformers import pipeline
79
+
80
+ # Load model
81
+ classifier = pipeline(
82
+ "text-classification",
83
+ model="mrm8488/bert-tiny-finetuned-fake-news-detection"
84
+ )
85
+
86
+ def predict_news(text):
87
+ if text.strip() == "":
88
+ return "<span style='color:red;'>Please enter news text</span>", 0
89
+
90
+ result = classifier(text)[0]
91
+ label = result["label"]
92
+ confidence = round(result["score"] * 100, 2)
93
+
94
+ # Correct label mapping
95
+ if label == "LABEL_0":
96
+ display_label = "Fake"
97
+ color = "red"
98
+ else:
99
+ display_label = "Real"
100
+ color = "green"
101
+
102
+ html_output = f"""
103
+ <div style="
104
+ font-size:28px;
105
+ font-weight:bold;
106
+ color:{color};
107
+ text-align:center;
108
+ padding:20px;
109
+ ">
110
+ {display_label} {confidence}%
111
+ </div>
112
+ """
113
+
114
+ return html_output, confidence
115
+
116
+
117
+ # ================= UI LAYOUT =================
118
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
119
+
120
+ gr.Markdown(
121
+ """
122
+ # 📰 Fake News Detection System
123
+ ### AI-based system to detect Fake or Real news (English & Bangla)
124
+ """
125
+ )
126
+
127
+ with gr.Row():
128
+ with gr.Column(scale=2):
129
+ news_input = gr.Textbox(
130
+ label="Enter News Text",
131
+ placeholder="Paste English or Bangla news here...",
132
+ lines=10
133
+ )
134
+ submit_btn = gr.Button("Submit", variant="primary")
135
+
136
+ with gr.Column(scale=1):
137
+ prediction_output = gr.HTML(label="Prediction")
138
+ confidence_bar = gr.Slider(
139
+ minimum=0,
140
+ maximum=100,
141
+ label="Confidence Percentage",
142
  interactive=False
143
  )
144