Aryan Mishra commited on
Commit
0ca1086
·
1 Parent(s): aba9503

Apply theme/CSS when creating Gradio Blocks

Browse files

Move the `custom_css` definition before UI construction and pass both `theme` and `css` directly into `gr.Blocks(...)` instead of `demo.launch(...)`. This keeps styling configuration attached to the app object and simplifies startup with a plain `demo.launch()`.

Files changed (1) hide show
  1. app.py +90 -88
app.py CHANGED
@@ -324,7 +324,94 @@ custom_theme = gr.themes.Soft(
324
  color_accent_soft_dark="#EFF6FF",
325
  )
326
 
327
- with gr.Blocks(title="Multilingual ABSA") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
  # TOP HEADER
330
  with gr.Row(elem_classes="top-header"):
@@ -421,92 +508,7 @@ with gr.Blocks(title="Multilingual ABSA") as demo:
421
  refresh_btn.click(fn=get_history_rows, outputs=history_df)
422
  clear_btn.click(fn=clear_history, outputs=[history_df]).then(fn=get_history_rows, outputs=history_df)
423
 
424
- custom_css = """
425
- /* 60/30/10 Design System */
426
-
427
- /* Layout & Base */
428
- .gradio-container { max-width: 1200px !important; margin: auto; font-family: 'Inter', sans-serif; padding: 24px !important; }
429
-
430
- /* Typography */
431
- .section-title { font-size: 1.1rem; font-weight: 600; color: #0F172A; margin-bottom: 4px; }
432
- .section-sub { font-size: 0.9rem; color: #64748B; margin-bottom: 16px; }
433
-
434
- /* Top Header */
435
- .top-header { border-bottom: 1px solid #E2E8F0; padding-bottom: 16px; margin-bottom: 24px; align-items: center; }
436
- .header-content h1 { font-size: 1.6rem; font-weight: 600; color: #0F172A; margin: 0 0 4px 0; letter-spacing: -0.02em; }
437
- .header-subtitle { font-size: 0.9rem; color: #64748B; }
438
-
439
- /* Header Metrics */
440
- .header-metrics { display: flex; gap: 24px; justify-content: flex-end; flex-wrap: wrap; }
441
- .metric { display: flex; flex-direction: column; }
442
- .m-label { font-size: 0.65rem; font-weight: 600; color: #64748B; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
443
- .m-val { font-size: 0.85rem; font-weight: 500; color: #0F172A; }
444
- .status-dot { color: #16A34A; margin-right: 4px; }
445
-
446
- /* Panels */
447
- .workspace-row { gap: 32px !important; align-items: flex-start !important; }
448
- .panel { background: #FFFFFF; border: 1px solid #E2E8F0; border-radius: 8px; padding: 24px; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
449
-
450
- /* Review Input */
451
- .review-input textarea { border: 1px solid #CBD5E1 !important; border-radius: 6px !important; padding: 12px !important; font-size: 0.95rem !important; line-height: 1.5 !important; background: #FFFFFF !important; color: #0F172A !important; transition: border-color 0.2s; box-shadow: none !important; }
452
- .review-input textarea:focus { border-color: #2563EB !important; ring: 1px solid #2563EB !important; }
453
- .analyze-btn { background: #2563EB !important; color: #FFFFFF !important; font-weight: 500 !important; border-radius: 6px !important; margin-top: 16px !important; padding: 10px 0 !important; border: none !important; transition: background 0.2s !important; }
454
- .analyze-btn:hover { background: #1D4ED8 !important; }
455
-
456
- /* Examples */
457
- .compact-examples .gallery { gap: 8px !important; }
458
- .compact-examples button { border: 1px solid #E2E8F0 !important; border-radius: 6px !important; padding: 8px 12px !important; font-size: 0.8rem !important; background: #F8FAFC !important; color: #475569 !important; text-align: left !important; }
459
- .compact-examples button:hover { background: #F1F5F9 !important; border-color: #CBD5E1 !important; }
460
-
461
- /* Meta Badges */
462
- .meta-badges { display: flex; gap: 12px; margin-bottom: 24px; }
463
- .badge { font-size: 0.75rem; background: #F1F5F9; color: #475569; padding: 4px 10px; border-radius: 4px; border: 1px solid #E2E8F0; }
464
- .badge strong { color: #0F172A; font-weight: 600; margin-left: 4px; }
465
-
466
- /* Summary Vis */
467
- .summary-vis { margin-bottom: 24px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.8rem; }
468
- .summary-title { font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 600; color: #0F172A; margin-bottom: 12px; border-bottom: 1px solid #E2E8F0; padding-bottom: 8px; }
469
- .vis-row { margin-bottom: 6px; display: flex; align-items: center; gap: 12px; color: #475569; }
470
- .vis-block { letter-spacing: -1px; font-size: 0.7rem; }
471
- .vis-block.pos { color: #16A34A; }
472
- .vis-block.neg { color: #DC2626; }
473
- .vis-block.neu { color: #64748B; }
474
- .vis-block.empty-block { visibility: hidden; width: 10px; }
475
- .summary-vis.empty { font-family: 'Inter', sans-serif; color: #64748B; font-style: italic; }
476
-
477
- /* Results Table */
478
- .results-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 0.85rem; }
479
- .results-table th { text-align: left; padding: 8px 12px; border-bottom: 1px solid #E2E8F0; color: #64748B; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
480
- .results-table td { padding: 12px; border-bottom: 1px solid #F1F5F9; color: #0F172A; }
481
- .aspect-col { font-weight: 500; }
482
- .sentiment-col { display: flex; align-items: center; gap: 6px; }
483
- .sent-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
484
-
485
- /* Confidence Bar */
486
- .conf-col { min-width: 120px; }
487
- .conf-bar-bg { width: 60px; height: 6px; background: #E2E8F0; border-radius: 3px; display: inline-block; vertical-align: middle; margin-right: 8px; overflow: hidden; }
488
- .conf-bar-fill { height: 100%; background: #2563EB; border-radius: 3px; }
489
- .conf-val { font-family: ui-monospace, monospace; font-size: 0.8rem; color: #475569; }
490
-
491
- .empty-state { padding: 32px 0; text-align: center; color: #64748B; font-size: 0.9rem; border: 1px dashed #CBD5E1; border-radius: 6px; }
492
-
493
- /* Raw Output Accordion */
494
- .raw-accordion { margin-top: 24px !important; border: 1px solid #E2E8F0 !important; border-radius: 6px !important; overflow: hidden !important; background: #FFFFFF !important; }
495
- .raw-accordion .label-wrap { padding: 12px 16px !important; font-size: 0.85rem !important; font-weight: 600 !important; color: #0F172A !important; background: #F8FAFC !important; border-bottom: 1px solid #E2E8F0 !important; }
496
- .raw-accordion .raw-json { background: #0F172A !important; padding: 16px !important; margin: 0 !important; }
497
- .raw-accordion .raw-json * { color: #F8FAFC !important; font-family: ui-monospace, SFMono-Regular, monospace !important; font-size: 0.8rem !important; }
498
-
499
- /* History Table */
500
- .history-table { border: 1px solid #E2E8F0 !important; border-radius: 8px !important; overflow: hidden !important; margin-top: 16px !important; }
501
- .history-table th { background: #F8FAFC !important; color: #475569 !important; font-size: 0.75rem !important; text-transform: uppercase !important; font-weight: 600 !important; }
502
-
503
- /* Mobile Stacking */
504
- @media (max-width: 768px) {
505
- .workspace-row { flex-direction: column !important; }
506
- .panel { width: 100% !important; }
507
- .header-metrics { justify-content: flex-start; margin-top: 16px; }
508
- }
509
- """
510
 
511
  if __name__ == "__main__":
512
- demo.launch(theme=custom_theme, css=custom_css)
 
324
  color_accent_soft_dark="#EFF6FF",
325
  )
326
 
327
+ custom_css = """
328
+ /* 60/30/10 Design System */
329
+
330
+ /* Layout & Base */
331
+ .gradio-container { max-width: 1200px !important; margin: auto; font-family: 'Inter', sans-serif; padding: 24px !important; }
332
+
333
+ /* Typography */
334
+ .section-title { font-size: 1.1rem; font-weight: 600; color: #0F172A; margin-bottom: 4px; }
335
+ .section-sub { font-size: 0.9rem; color: #64748B; margin-bottom: 16px; }
336
+
337
+ /* Top Header */
338
+ .top-header { border-bottom: 1px solid #E2E8F0; padding-bottom: 16px; margin-bottom: 24px; align-items: center; }
339
+ .header-content h1 { font-size: 1.6rem; font-weight: 600; color: #0F172A; margin: 0 0 4px 0; letter-spacing: -0.02em; }
340
+ .header-subtitle { font-size: 0.9rem; color: #64748B; }
341
+
342
+ /* Header Metrics */
343
+ .header-metrics { display: flex; gap: 24px; justify-content: flex-end; flex-wrap: wrap; }
344
+ .metric { display: flex; flex-direction: column; }
345
+ .m-label { font-size: 0.65rem; font-weight: 600; color: #64748B; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
346
+ .m-val { font-size: 0.85rem; font-weight: 500; color: #0F172A; }
347
+ .status-dot { color: #16A34A; margin-right: 4px; }
348
+
349
+ /* Panels */
350
+ .workspace-row { gap: 32px !important; align-items: flex-start !important; }
351
+ .panel { background: #FFFFFF; border: 1px solid #E2E8F0; border-radius: 8px; padding: 24px; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
352
+
353
+ /* Review Input */
354
+ .review-input textarea { border: 1px solid #CBD5E1 !important; border-radius: 6px !important; padding: 12px !important; font-size: 0.95rem !important; line-height: 1.5 !important; background: #FFFFFF !important; color: #0F172A !important; transition: border-color 0.2s; box-shadow: none !important; }
355
+ .review-input textarea:focus { border-color: #2563EB !important; ring: 1px solid #2563EB !important; }
356
+ .analyze-btn { background: #2563EB !important; color: #FFFFFF !important; font-weight: 500 !important; border-radius: 6px !important; margin-top: 16px !important; padding: 10px 0 !important; border: none !important; transition: background 0.2s !important; }
357
+ .analyze-btn:hover { background: #1D4ED8 !important; }
358
+
359
+ /* Examples */
360
+ .compact-examples .gallery { gap: 8px !important; }
361
+ .compact-examples button { border: 1px solid #E2E8F0 !important; border-radius: 6px !important; padding: 8px 12px !important; font-size: 0.8rem !important; background: #F8FAFC !important; color: #475569 !important; text-align: left !important; }
362
+ .compact-examples button:hover { background: #F1F5F9 !important; border-color: #CBD5E1 !important; }
363
+
364
+ /* Meta Badges */
365
+ .meta-badges { display: flex; gap: 12px; margin-bottom: 24px; }
366
+ .badge { font-size: 0.75rem; background: #F1F5F9; color: #475569; padding: 4px 10px; border-radius: 4px; border: 1px solid #E2E8F0; }
367
+ .badge strong { color: #0F172A; font-weight: 600; margin-left: 4px; }
368
+
369
+ /* Summary Vis */
370
+ .summary-vis { margin-bottom: 24px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.8rem; }
371
+ .summary-title { font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 600; color: #0F172A; margin-bottom: 12px; border-bottom: 1px solid #E2E8F0; padding-bottom: 8px; }
372
+ .vis-row { margin-bottom: 6px; display: flex; align-items: center; gap: 12px; color: #475569; }
373
+ .vis-block { letter-spacing: -1px; font-size: 0.7rem; }
374
+ .vis-block.pos { color: #16A34A; }
375
+ .vis-block.neg { color: #DC2626; }
376
+ .vis-block.neu { color: #64748B; }
377
+ .vis-block.empty-block { visibility: hidden; width: 10px; }
378
+ .summary-vis.empty { font-family: 'Inter', sans-serif; color: #64748B; font-style: italic; }
379
+
380
+ /* Results Table */
381
+ .results-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 0.85rem; }
382
+ .results-table th { text-align: left; padding: 8px 12px; border-bottom: 1px solid #E2E8F0; color: #64748B; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
383
+ .results-table td { padding: 12px; border-bottom: 1px solid #F1F5F9; color: #0F172A; }
384
+ .aspect-col { font-weight: 500; }
385
+ .sentiment-col { display: flex; align-items: center; gap: 6px; }
386
+ .sent-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
387
+
388
+ /* Confidence Bar */
389
+ .conf-col { min-width: 120px; }
390
+ .conf-bar-bg { width: 60px; height: 6px; background: #E2E8F0; border-radius: 3px; display: inline-block; vertical-align: middle; margin-right: 8px; overflow: hidden; }
391
+ .conf-bar-fill { height: 100%; background: #2563EB; border-radius: 3px; }
392
+ .conf-val { font-family: ui-monospace, monospace; font-size: 0.8rem; color: #475569; }
393
+
394
+ .empty-state { padding: 32px 0; text-align: center; color: #64748B; font-size: 0.9rem; border: 1px dashed #CBD5E1; border-radius: 6px; }
395
+
396
+ /* Raw Output Accordion */
397
+ .raw-accordion { margin-top: 24px !important; border: 1px solid #E2E8F0 !important; border-radius: 6px !important; overflow: hidden !important; background: #FFFFFF !important; }
398
+ .raw-accordion .label-wrap { padding: 12px 16px !important; font-size: 0.85rem !important; font-weight: 600 !important; color: #0F172A !important; background: #F8FAFC !important; border-bottom: 1px solid #E2E8F0 !important; }
399
+ .raw-accordion .raw-json { background: #0F172A !important; padding: 16px !important; margin: 0 !important; }
400
+ .raw-accordion .raw-json * { color: #F8FAFC !important; font-family: ui-monospace, SFMono-Regular, monospace !important; font-size: 0.8rem !important; }
401
+
402
+ /* History Table */
403
+ .history-table { border: 1px solid #E2E8F0 !important; border-radius: 8px !important; overflow: hidden !important; margin-top: 16px !important; }
404
+ .history-table th { background: #F8FAFC !important; color: #475569 !important; font-size: 0.75rem !important; text-transform: uppercase !important; font-weight: 600 !important; }
405
+
406
+ /* Mobile Stacking */
407
+ @media (max-width: 768px) {
408
+ .workspace-row { flex-direction: column !important; }
409
+ .panel { width: 100% !important; }
410
+ .header-metrics { justify-content: flex-start; margin-top: 16px; }
411
+ }
412
+ """
413
+
414
+ with gr.Blocks(title="Multilingual ABSA", theme=custom_theme, css=custom_css) as demo:
415
 
416
  # TOP HEADER
417
  with gr.Row(elem_classes="top-header"):
 
508
  refresh_btn.click(fn=get_history_rows, outputs=history_df)
509
  clear_btn.click(fn=clear_history, outputs=[history_df]).then(fn=get_history_rows, outputs=history_df)
510
 
511
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
 
513
  if __name__ == "__main__":
514
+ demo.launch()