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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -40
app.py CHANGED
@@ -30,7 +30,7 @@ def classify(text: str):
30
 
31
 
32
  # --------------------------
33
- # Shared CSS (glass design)
34
  # --------------------------
35
  custom_css = """
36
  body {
@@ -67,13 +67,6 @@ body {
67
  font-size: 11px;
68
  opacity: 0.7;
69
  }
70
- .nav-link {
71
- font-size: 13px;
72
- opacity: 0.85;
73
- }
74
- .nav-link-active {
75
- font-weight: 600;
76
- }
77
  .btn-primary-custom {
78
  background: linear-gradient(135deg, #21c38f, #1ab07f) !important;
79
  color: #041110 !important;
@@ -146,13 +139,10 @@ textarea {
146
  """
147
 
148
 
149
- def navbar(active: str):
150
- """Small helper to render the top nav HTML with active link highlighted."""
151
- def cls(name):
152
- return "nav-link nav-link-active" if name == active else "nav-link"
153
-
154
  return gr.HTML(
155
- f"""
156
  <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:18px;">
157
  <div style="display:flex;align-items:center;gap:10px;">
158
  <div class="nav-logo"></div>
@@ -161,11 +151,11 @@ def navbar(active: str):
161
  <div class="nav-subtitle">Cebuano Misinformation Detector</div>
162
  </div>
163
  </div>
164
- <div style="display:flex;gap:24px;">
165
- <a class="{cls('Analyzer')}" href="#/analyzer">Analyzer</a>
166
- <a class="{cls('How')}" href="#/how-it-works">How it works</a>
167
- <a class="{cls('About')}" href="#/about">About</a>
168
- <a class="{cls('Feedback')}" href="#/feedback">Feedback</a>
169
  </div>
170
  </div>
171
  """
@@ -173,14 +163,12 @@ def navbar(active: str):
173
 
174
 
175
  # --------------------------
176
- # Build multipage app
177
  # --------------------------
178
  with gr.Blocks(fill_height=True) as demo:
 
179
 
180
- # ------------- Analyzer page -------------
181
- with gr.Page(name="analyzer"):
182
- navbar("Analyzer")
183
-
184
  gr.HTML(
185
  """
186
  <section style="margin-bottom:18px;">
@@ -243,7 +231,6 @@ with gr.Blocks(fill_height=True) as demo:
243
  "Output: Label and confidence score for the submitted text."
244
  )
245
 
246
- # backend → UI glue
247
  def analyze_ui(text):
248
  probs = classify(text)
249
  fake_p = probs.get("fake", 0.0)
@@ -278,9 +265,8 @@ with gr.Blocks(fill_height=True) as demo:
278
  )
279
  clear_btn.click(fn=lambda: "", inputs=None, outputs=[news_text])
280
 
281
- # ------------- How it works page -------------
282
- with gr.Page(name="how-it-works"):
283
- navbar("How")
284
  with gr.Group(elem_classes=["glass-card"]):
285
  gr.Markdown(
286
  "## How CMD‑BERT works\n"
@@ -313,9 +299,8 @@ with gr.Blocks(fill_height=True) as demo:
313
  "- Final judgment should always involve human critical thinking."
314
  )
315
 
316
- # ------------- About page -------------
317
- with gr.Page(name="about"):
318
- navbar("About")
319
  with gr.Group(elem_classes=["glass-card"]):
320
  gr.Markdown(
321
  "## About CMD‑BERT\n"
@@ -340,9 +325,8 @@ with gr.Blocks(fill_height=True) as demo:
340
  "January 2026"
341
  )
342
 
343
- # ------------- Feedback page -------------
344
- with gr.Page(name="feedback"):
345
- navbar("Feedback")
346
  with gr.Group(elem_classes=["glass-card"]):
347
  gr.Markdown(
348
  "## Feedback and model improvement\n"
@@ -374,10 +358,7 @@ with gr.Blocks(fill_height=True) as demo:
374
 
375
  with gr.Column():
376
  with gr.Group(elem_classes=["glass-card"]):
377
- fb_status = gr.Markdown(
378
- "No feedback submitted yet.",
379
- label=""
380
- )
381
  gr.Markdown(
382
  "### FAQ\n"
383
  "**What happens to my feedback?** \n"
@@ -391,7 +372,6 @@ with gr.Blocks(fill_height=True) as demo:
391
  def save_feedback(ftype, text, email, consent):
392
  if not text.strip():
393
  return "Please enter a message before submitting."
394
- # For now just acknowledge; you can extend this to write to a file or database.
395
  return "Thank you for your feedback! It has been recorded."
396
 
397
  fb_submit.click(
@@ -402,4 +382,4 @@ with gr.Blocks(fill_height=True) as demo:
402
 
403
 
404
  if __name__ == "__main__":
405
- demo.launch(css=custom_css, theme=gr.themes.Soft())
 
30
 
31
 
32
  # --------------------------
33
+ # Shared CSS
34
  # --------------------------
35
  custom_css = """
36
  body {
 
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;
 
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>
 
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
  """
 
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;">
 
231
  "Output: Label and confidence score for the submitted text."
232
  )
233
 
 
234
  def analyze_ui(text):
235
  probs = classify(text)
236
  fake_p = probs.get("fake", 0.0)
 
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(
272
  "## How CMD‑BERT works\n"
 
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(
306
  "## About CMD‑BERT\n"
 
325
  "January 2026"
326
  )
327
 
328
+ # -------- Feedback tab --------
329
+ with gr.Tab("Feedback"):
 
330
  with gr.Group(elem_classes=["glass-card"]):
331
  gr.Markdown(
332
  "## Feedback and model improvement\n"
 
358
 
359
  with gr.Column():
360
  with gr.Group(elem_classes=["glass-card"]):
361
+ fb_status = gr.Markdown("No feedback submitted yet.")
 
 
 
362
  gr.Markdown(
363
  "### FAQ\n"
364
  "**What happens to my feedback?** \n"
 
372
  def save_feedback(ftype, text, email, consent):
373
  if not text.strip():
374
  return "Please enter a message before submitting."
 
375
  return "Thank you for your feedback! It has been recorded."
376
 
377
  fb_submit.click(
 
382
 
383
 
384
  if __name__ == "__main__":
385
+ demo.launch(css=custom_css, theme=gr.themes.Soft())