roncc13 commited on
Commit
6bd8fc9
·
verified ·
1 Parent(s): 192d55d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -100
app.py CHANGED
@@ -2,9 +2,6 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
5
- # --------------------------
6
- # Model setup
7
- # --------------------------
8
  MODEL_ID = "roncc13/trainCMDBERT-sample"
9
 
10
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
@@ -29,75 +26,57 @@ def classify(text: str):
29
  return {label_names[i]: float(probs[i]) for i in range(len(label_names))}
30
 
31
 
32
- # --------------------------
33
- # Shared CSS
34
- # --------------------------
35
  custom_css = """
36
  body {
37
- background: radial-gradient(circle at top left, #2b2c4a 0, #121320 45%, #080910 100%);
38
  }
39
  .gradio-container {
40
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
41
  "Segoe UI", sans-serif;
42
- max-width: 1100px !important;
43
  margin: 0 auto !important;
44
- padding: 20px 10px 40px 10px !important;
45
  color: #f5f6ff;
46
  }
47
  .glass-card {
48
- background: linear-gradient(145deg, rgba(255,255,255,0.12), rgba(255,255,255,0.03));
49
- border-radius: 18px;
50
  border: 1px solid rgba(255,255,255,0.16);
51
- box-shadow: 0 18px 45px rgba(0,0,0,0.6);
52
- padding: 18px 20px;
53
- backdrop-filter: blur(14px);
54
  }
55
- .nav-logo {
56
- width: 24px;
57
- height: 24px;
58
- border-radius: 8px;
59
- background: linear-gradient(135deg, #ffffff, #c1c5ff);
60
- }
61
- .nav-title {
62
- font-weight: 600;
63
- letter-spacing: 0.04em;
64
- font-size: 14px;
65
  }
66
- .nav-subtitle {
67
- font-size: 11px;
68
- opacity: 0.7;
 
69
  }
70
  .btn-primary-custom {
71
- background: linear-gradient(135deg, #21c38f, #1ab07f) !important;
72
  color: #041110 !important;
73
  border-radius: 999px !important;
74
  border: none !important;
75
- padding: 8px 22px !important;
76
  font-weight: 600 !important;
77
- box-shadow: 0 12px 25px rgba(8, 160, 110, 0.55);
78
  }
79
  .btn-secondary-custom {
80
- background: transparent !important;
81
- color: rgba(245,246,255,0.85) !important;
82
  border-radius: 999px !important;
83
- border: 1px solid rgba(255,255,255,0.2) !important;
84
- padding: 8px 18px !important;
85
  font-size: 11px !important;
86
  }
87
- .hero-title {
88
- font-size: 30px;
89
- font-weight: 700;
90
- letter-spacing: 0.02em;
91
- line-height: 1.15;
92
- }
93
- .hero-subtitle {
94
- margin-top: 8px;
95
- font-size: 13px;
96
- max-width: 520px;
97
- opacity: 0.85;
98
- }
99
  .conf-bar-bg {
100
- margin-top: 10px;
101
  width: 100%;
102
  height: 8px;
103
  border-radius: 999px;
@@ -126,8 +105,8 @@ body {
126
  }
127
  textarea {
128
  background: #050515 !important;
129
- border-radius: 10px !important;
130
- border: 1px solid rgba(255,255,255,0.08) !important;
131
  color: #f5f6ff !important;
132
  font-size: 13px !important;
133
  }
@@ -139,56 +118,34 @@ textarea {
139
  """
140
 
141
 
142
- def navbar():
143
- """Top bar shared by all tabs."""
144
- return gr.HTML(
145
- """
146
- <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:18px;">
147
- <div style="display:flex;align-items:center;gap:10px;">
148
- <div class="nav-logo"></div>
149
- <div>
150
- <div class="nav-title">CMD‑BERT</div>
151
- <div class="nav-subtitle">Cebuano Misinformation Detector</div>
152
- </div>
153
- </div>
154
- <div style="display:flex;gap:24px;font-size:13px;opacity:0.85;">
155
- <span>Analyzer</span>
156
- <span>How it works</span>
157
- <span>About</span>
158
- <span>Feedback</span>
159
- </div>
160
- </div>
161
- """
162
- )
163
-
164
-
165
- # --------------------------
166
- # Single Blocks app with Tabs
167
- # --------------------------
168
  with gr.Blocks(fill_height=True) as demo:
169
- navbar()
 
170
 
171
  with gr.Tab("Analyzer"):
172
- gr.HTML(
173
- """
174
- <section style="margin-bottom:18px;">
175
- <div class="hero-title">
176
- Check Cebuano text for a misleading writing style.
177
- </div>
178
- <div class="hero-subtitle">
179
- Paste a headline, post, or short article. CMD‑BERT returns a label
180
- (Fake or Legit) and a confidence score based on writing patterns.
181
- </div>
182
- </section>
183
- """
184
- )
 
 
 
185
 
186
- with gr.Row(elem_classes=["two-col"]):
187
  # Left: input card
188
  with gr.Column(scale=3):
189
  with gr.Group(elem_classes=["glass-card"]):
190
  gr.Markdown(
191
- "### Text input\n"
192
  "Cebuano only. This tool checks linguistic patterns; it does not verify facts."
193
  )
194
  gr.Markdown(
@@ -205,19 +162,21 @@ with gr.Blocks(fill_height=True) as demo:
205
  analyze_btn = gr.Button("Analyze", elem_classes=["btn-primary-custom"])
206
  clear_btn = gr.Button("Clear", elem_classes=["btn-secondary-custom"])
207
  gr.Markdown(
 
208
  "Tip: Keep inputs under 1,000 characters for faster results."
 
209
  )
210
 
211
  # Right: result card
212
  with gr.Column(scale=2):
213
  with gr.Group(elem_classes=["glass-card"]):
214
- gr.Markdown("### Result")
215
  result_label_html = gr.HTML(
216
  '<span class="badge-pill badge-fake">FAKE</span>'
217
  )
218
  conf_text = gr.HTML(
219
- '<div style="display:flex;align-items:flex-end;gap:6px;margin-top:8px;">'
220
- '<span style="font-size:26px;font-weight:600;" id="conf-val">0.00</span>'
221
  '<span style="font-size:12px;opacity:0.8;">confidence</span>'
222
  '</div>'
223
  )
@@ -227,8 +186,10 @@ with gr.Blocks(fill_height=True) as demo:
227
  '</div>'
228
  )
229
  gr.Markdown(
230
- "Model: CMD‑BERT (fine‑tuned BERT‑base). \n"
 
231
  "Output: Label and confidence score for the submitted text."
 
232
  )
233
 
234
  def analyze_ui(text):
@@ -246,8 +207,8 @@ with gr.Blocks(fill_height=True) as demo:
246
  conf_pct = int(conf * 100)
247
  label_html = f'<span class="{css_class}">{label}</span>'
248
  conf_html = (
249
- '<div style="display:flex;align-items:flex-end;gap:6px;margin-top:8px;">'
250
- f'<span style="font-size:26px;font-weight:600;" id="conf-val">{conf:.2f}</span>'
251
  '<span style="font-size:12px;opacity:0.8;">confidence</span>'
252
  '</div>'
253
  )
@@ -265,7 +226,7 @@ with gr.Blocks(fill_height=True) as demo:
265
  )
266
  clear_btn.click(fn=lambda: "", inputs=None, outputs=[news_text])
267
 
268
- # -------- How it works tab --------
269
  with gr.Tab("How it works"):
270
  with gr.Group(elem_classes=["glass-card"]):
271
  gr.Markdown(
@@ -299,7 +260,7 @@ with gr.Blocks(fill_height=True) as demo:
299
  "- Final judgment should always involve human critical thinking."
300
  )
301
 
302
- # -------- About tab --------
303
  with gr.Tab("About"):
304
  with gr.Group(elem_classes=["glass-card"]):
305
  gr.Markdown(
@@ -325,7 +286,7 @@ with gr.Blocks(fill_height=True) as demo:
325
  "January 2026"
326
  )
327
 
328
- # -------- Feedback tab --------
329
  with gr.Tab("Feedback"):
330
  with gr.Group(elem_classes=["glass-card"]):
331
  gr.Markdown(
 
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
 
 
 
5
  MODEL_ID = "roncc13/trainCMDBERT-sample"
6
 
7
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
 
26
  return {label_names[i]: float(probs[i]) for i in range(len(label_names))}
27
 
28
 
 
 
 
29
  custom_css = """
30
  body {
31
+ background: radial-gradient(circle at top left, #262845 0, #10111e 45%, #060712 100%);
32
  }
33
  .gradio-container {
34
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
35
  "Segoe UI", sans-serif;
36
+ max-width: 1120px !important;
37
  margin: 0 auto !important;
38
+ padding: 32px 16px 40px 16px !important;
39
  color: #f5f6ff;
40
  }
41
  .glass-card {
42
+ background: linear-gradient(145deg, rgba(255,255,255,0.12), rgba(255,255,255,0.02));
43
+ border-radius: 20px;
44
  border: 1px solid rgba(255,255,255,0.16);
45
+ box-shadow: 0 18px 45px rgba(0,0,0,0.7);
46
+ padding: 20px 22px;
47
+ backdrop-filter: blur(20px);
48
  }
49
+ .hero-title {
50
+ font-size: 30px;
51
+ font-weight: 700;
52
+ letter-spacing: 0.02em;
53
+ line-height: 1.2;
54
+ margin-bottom: 6px;
 
 
 
 
55
  }
56
+ .hero-subtitle {
57
+ font-size: 13px;
58
+ max-width: 560px;
59
+ opacity: 0.85;
60
  }
61
  .btn-primary-custom {
62
+ background: linear-gradient(135deg, #1fd39a, #19b984) !important;
63
  color: #041110 !important;
64
  border-radius: 999px !important;
65
  border: none !important;
66
+ padding: 10px 26px !important;
67
  font-weight: 600 !important;
68
+ box-shadow: 0 14px 30px rgba(11, 176, 123, 0.6);
69
  }
70
  .btn-secondary-custom {
71
+ background: rgba(255,255,255,0.02) !important;
72
+ color: rgba(245,246,255,0.90) !important;
73
  border-radius: 999px !important;
74
+ border: 1px solid rgba(255,255,255,0.25) !important;
75
+ padding: 10px 22px !important;
76
  font-size: 11px !important;
77
  }
 
 
 
 
 
 
 
 
 
 
 
 
78
  .conf-bar-bg {
79
+ margin-top: 12px;
80
  width: 100%;
81
  height: 8px;
82
  border-radius: 999px;
 
105
  }
106
  textarea {
107
  background: #050515 !important;
108
+ border-radius: 12px !important;
109
+ border: 1px solid rgba(255,255,255,0.12) !important;
110
  color: #f5f6ff !important;
111
  font-size: 13px !important;
112
  }
 
118
  """
119
 
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  with gr.Blocks(fill_height=True) as demo:
122
+ # top padding so content is not glued to the tabs
123
+ gr.HTML("<div style='height: 10px;'></div>")
124
 
125
  with gr.Tab("Analyzer"):
126
+ with gr.Row():
127
+ with gr.Column():
128
+ gr.HTML(
129
+ """
130
+ <section style="margin-bottom:22px;">
131
+ <div class="hero-title">
132
+ Check Cebuano text for a misleading writing style.
133
+ </div>
134
+ <div class="hero-subtitle">
135
+ Paste a headline, post, or short article. CMD‑BERT returns a label
136
+ (Fake or Legit) and a confidence score based on writing patterns.
137
+ It does not verify factual correctness.
138
+ </div>
139
+ </section>
140
+ """
141
+ )
142
 
143
+ with gr.Row(elem_classes=["two-col"], equal_height=True):
144
  # Left: input card
145
  with gr.Column(scale=3):
146
  with gr.Group(elem_classes=["glass-card"]):
147
  gr.Markdown(
148
+ "#### Text input\n"
149
  "Cebuano only. This tool checks linguistic patterns; it does not verify facts."
150
  )
151
  gr.Markdown(
 
162
  analyze_btn = gr.Button("Analyze", elem_classes=["btn-primary-custom"])
163
  clear_btn = gr.Button("Clear", elem_classes=["btn-secondary-custom"])
164
  gr.Markdown(
165
+ "<span style='font-size:11px;opacity:0.8;'>"
166
  "Tip: Keep inputs under 1,000 characters for faster results."
167
+ "</span>"
168
  )
169
 
170
  # Right: result card
171
  with gr.Column(scale=2):
172
  with gr.Group(elem_classes=["glass-card"]):
173
+ gr.Markdown("#### Result")
174
  result_label_html = gr.HTML(
175
  '<span class="badge-pill badge-fake">FAKE</span>'
176
  )
177
  conf_text = gr.HTML(
178
+ '<div style="display:flex;align-items:flex-end;gap:6px;margin-top:10px;">'
179
+ '<span style="font-size:28px;font-weight:600;" id="conf-val">0.00</span>'
180
  '<span style="font-size:12px;opacity:0.8;">confidence</span>'
181
  '</div>'
182
  )
 
186
  '</div>'
187
  )
188
  gr.Markdown(
189
+ "<span style='font-size:11px;opacity:0.85;'>"
190
+ "Model: CMD‑BERT (fine‑tuned BERT‑base). "
191
  "Output: Label and confidence score for the submitted text."
192
+ "</span>"
193
  )
194
 
195
  def analyze_ui(text):
 
207
  conf_pct = int(conf * 100)
208
  label_html = f'<span class="{css_class}">{label}</span>'
209
  conf_html = (
210
+ '<div style="display:flex;align-items:flex-end;gap:6px;margin-top:10px;">'
211
+ f'<span style="font-size:28px;font-weight:600;" id="conf-val">{conf:.2f}</span>'
212
  '<span style="font-size:12px;opacity:0.8;">confidence</span>'
213
  '</div>'
214
  )
 
226
  )
227
  clear_btn.click(fn=lambda: "", inputs=None, outputs=[news_text])
228
 
229
+ # --- How it works tab ---
230
  with gr.Tab("How it works"):
231
  with gr.Group(elem_classes=["glass-card"]):
232
  gr.Markdown(
 
260
  "- Final judgment should always involve human critical thinking."
261
  )
262
 
263
+ # --- About tab ---
264
  with gr.Tab("About"):
265
  with gr.Group(elem_classes=["glass-card"]):
266
  gr.Markdown(
 
286
  "January 2026"
287
  )
288
 
289
+ # --- Feedback tab ---
290
  with gr.Tab("Feedback"):
291
  with gr.Group(elem_classes=["glass-card"]):
292
  gr.Markdown(