TomLii commited on
Commit
8a78e83
·
1 Parent(s): 4b3dbbd

Polish UI: Gradio 5 theme overrides and container-scoped CSS

Browse files
Files changed (1) hide show
  1. app.py +161 -118
app.py CHANGED
@@ -60,62 +60,75 @@ SEARCH_CACHE: Dict[str, Dict[str, Any]] = {}
60
  VISIT_CACHE: Dict[str, Dict[str, Any]] = {}
61
  LOGO_PATH = str(Path(__file__).resolve().parent / "assets" / "quest-logo.png")
62
 
63
- CUSTOM_CSS = """
64
- @import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- .gradio-container {
 
 
67
  max-width: 1200px !important;
68
- font-family: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
69
- background: #f3f8ff !important;
70
- color: #0b2a66;
71
- }
72
-
73
- .gradio-container * {
74
- font-family: inherit !important;
75
- }
76
-
77
- .banner-card {
78
- padding: 18px 20px;
79
- border-radius: 18px;
80
- background: linear-gradient(100deg, #f8fbff 0%, #eef5ff 100%);
81
- color: #0f172a;
82
- border: 1px solid #dbe7ff;
83
- box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
84
- margin-bottom: 14px;
85
- }
86
-
87
- .banner-inner {
88
- display: flex;
89
- align-items: center;
90
- gap: 18px;
91
- }
92
-
93
- .banner-logo-wrap {
94
- min-width: 250px;
95
  }
96
 
97
- .banner-logo-image img {
 
 
98
  width: 100%;
99
  max-width: 360px;
100
  height: auto;
101
  object-fit: contain;
102
- border-radius: 0;
103
- background: transparent;
104
- border: none;
105
- }
106
-
107
- .banner-title {
108
- font-size: 24px;
109
- font-weight: 700;
110
- line-height: 1.15;
111
- color: #1e3a8a;
112
  }
113
 
114
- .banner-subtitle {
115
- margin-top: 6px;
116
- opacity: 0.9;
117
- font-size: 14px;
118
- color: #1f2937;
119
  }
120
 
121
  .section-card {
@@ -126,26 +139,30 @@ CUSTOM_CSS = """
126
  box-shadow: none !important;
127
  }
128
 
129
- .section-title {
130
- font-size: 13px;
131
  font-weight: 700;
132
- color: #2454b8;
133
- margin-bottom: 6px;
134
- letter-spacing: 0.02em;
 
 
 
135
  }
136
 
137
  .layout-gap {
138
- gap: 18px;
 
139
  }
140
 
141
  .right-stack > * {
142
- margin-bottom: 8px;
143
  }
144
 
145
  .icon-grid {
146
  display: grid;
147
  grid-template-columns: repeat(2, minmax(0, 1fr));
148
- gap: 10px;
149
  width: 100%;
150
  max-width: 360px;
151
  margin: 0 auto;
@@ -156,81 +173,106 @@ CUSTOM_CSS = """
156
  align-items: center;
157
  justify-content: center;
158
  gap: 8px;
159
- padding: 12px 14px;
160
- border: none;
161
- border-radius: 12px;
162
  text-decoration: none !important;
163
  color: #1d4ed8 !important;
164
- background: #eaf2ff;
165
  font-weight: 600;
166
  font-size: 17px;
 
 
 
167
  }
168
 
169
  .icon-link:hover {
170
- background: #dbeafe;
 
171
  }
172
 
173
- .gradio-container .gr-button-primary {
174
- background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%) !important;
175
  color: white !important;
176
  border: none !important;
177
- box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25) !important;
178
  }
179
 
180
- .gradio-container .gr-button-secondary {
181
  background: #ffffff !important;
182
  color: #1d4ed8 !important;
183
- border: 1px solid #bfdbfe !important;
184
- box-shadow: inset 0 0 0 1px #bfdbfe !important;
185
  }
186
 
187
- .gradio-container .gr-button-stop {
 
 
 
 
188
  background: #ffffff !important;
189
  color: #1d4ed8 !important;
190
- border: 1px solid #bfdbfe !important;
191
- box-shadow: inset 0 0 0 1px #bfdbfe !important;
192
  }
193
 
194
- .gradio-container .gr-group,
195
- .gradio-container .gr-box,
196
- .gradio-container .gr-panel {
197
- border: none !important;
198
- box-shadow: none !important;
199
- background: transparent !important;
200
  }
201
 
202
- .gradio-container .tabs {
 
 
 
203
  border: none !important;
 
204
  background: transparent !important;
205
  }
206
 
207
- .gradio-container .tabitem {
208
- border: none !important;
 
209
  background: transparent !important;
 
 
210
  }
211
 
212
- .gradio-container .gr-form,
213
- .gradio-container .form {
214
  background: #ffffff !important;
 
 
 
215
  }
216
 
217
- .gradio-container textarea,
218
- .gradio-container input {
219
- background: #ffffff !important;
220
- border: none !important;
221
- box-shadow: inset 0 0 0 1px #dbeafe !important;
222
- border-radius: 12px !important;
223
  }
224
 
225
- .gradio-container .gr-markdown a {
 
 
 
 
 
 
226
  color: #1d4ed8 !important;
227
  }
228
 
 
 
 
 
 
 
229
  .inline-example-title {
230
- font-size: 13px;
231
  font-weight: 700;
232
- color: #2454b8;
233
- margin: 8px 0 2px 0;
 
 
234
  }
235
 
236
  .example-buttons {
@@ -240,9 +282,9 @@ CUSTOM_CSS = """
240
  }
241
 
242
  .example-note {
243
- color: #3b82f6;
244
  font-size: 12px;
245
- margin-top: 2px;
246
  }
247
 
248
  .no-frame {
@@ -265,49 +307,54 @@ CUSTOM_CSS = """
265
  background: #2563eb !important;
266
  }
267
 
268
- .gradio-container .noUi-target {
269
  border: none !important;
270
  box-shadow: none !important;
271
- background: #eaf2ff !important;
272
  }
273
 
274
- .gradio-container .noUi-connect {
275
  background: #2563eb !important;
276
  }
277
 
278
- .gradio-container .noUi-handle {
279
  border: none !important;
280
- box-shadow: 0 0 0 2px #2563eb !important;
281
  background: #ffffff !important;
282
  }
283
 
284
- .gradio-container [data-testid="block-examples"] {
285
- border: none !important;
286
- background: #eef4ff !important;
287
- border-radius: 12px !important;
288
- padding: 8px !important;
 
 
 
 
 
289
  }
290
 
291
- .gradio-container [data-testid="block-examples"] table,
292
- .gradio-container [data-testid="block-examples"] thead,
293
- .gradio-container [data-testid="block-examples"] tbody,
294
- .gradio-container [data-testid="block-examples"] tr,
295
- .gradio-container [data-testid="block-examples"] td {
296
  border: none !important;
297
  background: transparent !important;
298
  }
299
 
300
- .gradio-container [data-testid="block-examples"] button {
301
  background: #ffffff !important;
302
  color: #1d4ed8 !important;
303
  border: none !important;
304
- border-radius: 10px !important;
305
- box-shadow: inset 0 0 0 1px #bfdbfe !important;
306
  font-size: 13px !important;
307
  }
308
 
309
- .gradio-container [data-testid="block-examples"] button:hover {
310
- background: #dbeafe !important;
311
  }
312
  """
313
 
@@ -598,17 +645,13 @@ def run_ui(
598
 
599
  with gr.Blocks(
600
  title="DeepResearch Space Starter",
601
- theme=gr.themes.Default(
602
- text_size="md",
603
- radius_size="md",
604
- spacing_size="md",
605
- ),
606
  css=CUSTOM_CSS,
607
  ) as demo:
608
  with gr.Row(elem_classes="layout-gap"):
609
  with gr.Column(scale=7):
610
  with gr.Group(elem_classes="section-card"):
611
- gr.HTML('<div class="section-title">Chat</div>')
612
  question = gr.Textbox(
613
  show_label=False,
614
  placeholder="Ask anything you want to research...",
@@ -659,7 +702,7 @@ with gr.Blocks(
659
  )
660
 
661
  with gr.Group(elem_classes="section-card"):
662
- gr.HTML('<div class="section-title">Settings</div>')
663
  model = gr.Dropdown(
664
  label="Model",
665
  choices=DEFAULT_FREE_MODELS,
 
60
  VISIT_CACHE: Dict[str, Dict[str, Any]] = {}
61
  LOGO_PATH = str(Path(__file__).resolve().parent / "assets" / "quest-logo.png")
62
 
63
+ # Gradio 5: neutral defaults read as grey; tune theme variables so panels/forms match the blue‑white UI.
64
+ APP_THEME = gr.themes.Soft(
65
+ primary_hue=gr.themes.colors.blue,
66
+ secondary_hue=gr.themes.colors.sky,
67
+ neutral_hue=gr.themes.colors.blue,
68
+ font=gr.themes.GoogleFont("Manrope"),
69
+ font_mono=gr.themes.GoogleFont("JetBrains Mono"),
70
+ ).set(
71
+ body_background_fill="#f3f8ff",
72
+ body_text_color="#0f2744",
73
+ body_text_color_subdued="#4a6a8c",
74
+ color_accent="*primary_600",
75
+ background_fill_primary="#ffffff",
76
+ background_fill_secondary="#e8f1ff",
77
+ border_color_primary="#c7dbfa",
78
+ border_color_accent="*primary_500",
79
+ block_background_fill="transparent",
80
+ block_border_width="0px",
81
+ block_border_color="transparent",
82
+ block_shadow="none",
83
+ block_label_background_fill="transparent",
84
+ block_label_border_width="0px",
85
+ block_title_border_width="0px",
86
+ panel_background_fill="transparent",
87
+ panel_border_width="0px",
88
+ panel_border_color="transparent",
89
+ input_background_fill="#ffffff",
90
+ input_border_color="#93c5fd",
91
+ input_border_width="1px",
92
+ input_shadow="none",
93
+ input_shadow_focus="none",
94
+ code_background_fill="#f0f7ff",
95
+ slider_color="*primary_500",
96
+ button_secondary_background_fill="#ffffff",
97
+ button_secondary_background_fill_hover="#eff6ff",
98
+ button_secondary_border_color="#93c5fd",
99
+ button_cancel_background_fill="#ffffff",
100
+ button_cancel_background_fill_hover="#eff6ff",
101
+ button_cancel_border_color="#93c5fd",
102
+ table_border_color="#dbeafe",
103
+ table_even_background_fill="#fafdff",
104
+ table_odd_background_fill="#ffffff",
105
+ )
106
 
107
+ CUSTOM_CSS = """
108
+ /* Gradio 5 uses versioned root classes (e.g. gradio-container-5-29-0); match all of them. */
109
+ [class*="gradio-container"] {
110
  max-width: 1200px !important;
111
+ color: #0f2744;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
 
114
+ .banner-logo-image img,
115
+ [class*="gradio-container"] .image-container img,
116
+ [class*="gradio-container"] .image-frame img {
117
  width: 100%;
118
  max-width: 360px;
119
  height: auto;
120
  object-fit: contain;
121
+ border-radius: 0 !important;
122
+ background: transparent !important;
123
+ border: none !important;
124
+ box-shadow: none !important;
 
 
 
 
 
 
125
  }
126
 
127
+ [class*="gradio-container"] .image-container,
128
+ [class*="gradio-container"] .image-frame {
129
+ border: none !important;
130
+ background: transparent !important;
131
+ box-shadow: none !important;
132
  }
133
 
134
  .section-card {
 
139
  box-shadow: none !important;
140
  }
141
 
142
+ .section-heading {
143
+ font-size: 0.72rem;
144
  font-weight: 700;
145
+ letter-spacing: 0.08em;
146
+ text-transform: uppercase;
147
+ color: #2563eb;
148
+ margin: 0 0 10px 0;
149
+ padding-bottom: 8px;
150
+ border-bottom: 1px solid rgba(37, 99, 235, 0.18);
151
  }
152
 
153
  .layout-gap {
154
+ gap: 20px;
155
+ align-items: flex-start;
156
  }
157
 
158
  .right-stack > * {
159
+ margin-bottom: 10px;
160
  }
161
 
162
  .icon-grid {
163
  display: grid;
164
  grid-template-columns: repeat(2, minmax(0, 1fr));
165
+ gap: 12px;
166
  width: 100%;
167
  max-width: 360px;
168
  margin: 0 auto;
 
173
  align-items: center;
174
  justify-content: center;
175
  gap: 8px;
176
+ padding: 14px 14px;
177
+ border-radius: 14px;
 
178
  text-decoration: none !important;
179
  color: #1d4ed8 !important;
180
+ background: linear-gradient(180deg, #ffffff 0%, #f0f7ff 100%);
181
  font-weight: 600;
182
  font-size: 17px;
183
+ box-shadow: 0 1px 0 rgba(37, 99, 235, 0.06), 0 8px 24px rgba(37, 99, 235, 0.08);
184
+ border: 1px solid rgba(147, 197, 253, 0.65);
185
+ transition: transform 0.15s ease, box-shadow 0.15s ease;
186
  }
187
 
188
  .icon-link:hover {
189
+ transform: translateY(-1px);
190
+ box-shadow: 0 4px 20px rgba(37, 99, 235, 0.12);
191
  }
192
 
193
+ [class*="gradio-container"] .gr-button-primary {
194
+ background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%) !important;
195
  color: white !important;
196
  border: none !important;
197
+ box-shadow: 0 8px 22px rgba(37, 99, 235, 0.28) !important;
198
  }
199
 
200
+ [class*="gradio-container"] .gr-button-secondary {
201
  background: #ffffff !important;
202
  color: #1d4ed8 !important;
203
+ border: 1px solid rgba(147, 197, 253, 0.9) !important;
204
+ box-shadow: 0 1px 2px rgba(15, 39, 68, 0.04) !important;
205
  }
206
 
207
+ [class*="gradio-container"] .gr-button-secondary:hover {
208
+ background: #f0f7ff !important;
209
+ }
210
+
211
+ [class*="gradio-container"] .gr-button-stop {
212
  background: #ffffff !important;
213
  color: #1d4ed8 !important;
214
+ border: 1px solid rgba(147, 197, 253, 0.9) !important;
215
+ box-shadow: 0 1px 2px rgba(15, 39, 68, 0.04) !important;
216
  }
217
 
218
+ [class*="gradio-container"] .gr-button-stop:hover {
219
+ background: #f0f7ff !important;
 
 
 
 
220
  }
221
 
222
+ [class*="gradio-container"] .gr-group,
223
+ [class*="gradio-container"] fieldset,
224
+ [class*="gradio-container"] .gr-box,
225
+ [class*="gradio-container"] .gr-panel {
226
  border: none !important;
227
+ box-shadow: none !important;
228
  background: transparent !important;
229
  }
230
 
231
+ /* Form rows use theme vars; keep chrome transparent so only inputs read as “cards”. */
232
+ [class*="gradio-container"] .gr-form,
233
+ [class*="gradio-container"] .form {
234
  background: transparent !important;
235
+ border: none !important;
236
+ box-shadow: none !important;
237
  }
238
 
239
+ [class*="gradio-container"] textarea,
240
+ [class*="gradio-container"] input:not([type="checkbox"]):not([type="radio"]) {
241
  background: #ffffff !important;
242
+ border: 1px solid rgba(147, 197, 253, 0.85) !important;
243
+ box-shadow: 0 6px 18px rgba(37, 99, 235, 0.06) !important;
244
+ border-radius: 14px !important;
245
  }
246
 
247
+ [class*="gradio-container"] textarea:focus,
248
+ [class*="gradio-container"] input:focus {
249
+ border-color: #3b82f6 !important;
250
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2) !important;
 
 
251
  }
252
 
253
+ [class*="gradio-container"] .gr-markdown,
254
+ [class*="gradio-container"] .prose {
255
+ color: #0f2744 !important;
256
+ }
257
+
258
+ [class*="gradio-container"] .gr-markdown a,
259
+ [class*="gradio-container"] .prose a {
260
  color: #1d4ed8 !important;
261
  }
262
 
263
+ /* Tabs: no heavy panels */
264
+ [class*="gradio-container"] .tabs {
265
+ border: none !important;
266
+ background: transparent !important;
267
+ }
268
+
269
  .inline-example-title {
270
+ font-size: 0.72rem;
271
  font-weight: 700;
272
+ letter-spacing: 0.08em;
273
+ text-transform: uppercase;
274
+ color: #2563eb;
275
+ margin: 16px 0 4px 0;
276
  }
277
 
278
  .example-buttons {
 
282
  }
283
 
284
  .example-note {
285
+ color: #4a6a8c;
286
  font-size: 12px;
287
+ margin: 0 0 6px 0;
288
  }
289
 
290
  .no-frame {
 
307
  background: #2563eb !important;
308
  }
309
 
310
+ [class*="gradio-container"] .noUi-target {
311
  border: none !important;
312
  box-shadow: none !important;
313
+ background: #e8f1ff !important;
314
  }
315
 
316
+ [class*="gradio-container"] .noUi-connect {
317
  background: #2563eb !important;
318
  }
319
 
320
+ [class*="gradio-container"] .noUi-handle {
321
  border: none !important;
322
+ box-shadow: 0 0 0 2px #2563eb, 0 2px 8px rgba(37, 99, 235, 0.2) !important;
323
  background: #ffffff !important;
324
  }
325
 
326
+ /* Example preset buttons live in normal Button blocks; soften any label chrome */
327
+ [class*="gradio-container"] .example-buttons .gr-form {
328
+ gap: 10px !important;
329
+ }
330
+
331
+ [class*="gradio-container"] [data-testid="block-examples"] {
332
+ background: linear-gradient(180deg, #f7fbff 0%, #eef4ff 100%) !important;
333
+ border-radius: 16px !important;
334
+ padding: 12px !important;
335
+ border: 1px solid rgba(147, 197, 253, 0.45) !important;
336
  }
337
 
338
+ [class*="gradio-container"] [data-testid="block-examples"] table,
339
+ [class*="gradio-container"] [data-testid="block-examples"] thead,
340
+ [class*="gradio-container"] [data-testid="block-examples"] tbody,
341
+ [class*="gradio-container"] [data-testid="block-examples"] tr,
342
+ [class*="gradio-container"] [data-testid="block-examples"] td {
343
  border: none !important;
344
  background: transparent !important;
345
  }
346
 
347
+ [class*="gradio-container"] [data-testid="block-examples"] button {
348
  background: #ffffff !important;
349
  color: #1d4ed8 !important;
350
  border: none !important;
351
+ border-radius: 12px !important;
352
+ box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.9) !important;
353
  font-size: 13px !important;
354
  }
355
 
356
+ [class*="gradio-container"] [data-testid="block-examples"] button:hover {
357
+ background: #eff6ff !important;
358
  }
359
  """
360
 
 
645
 
646
  with gr.Blocks(
647
  title="DeepResearch Space Starter",
648
+ theme=APP_THEME,
 
 
 
 
649
  css=CUSTOM_CSS,
650
  ) as demo:
651
  with gr.Row(elem_classes="layout-gap"):
652
  with gr.Column(scale=7):
653
  with gr.Group(elem_classes="section-card"):
654
+ gr.HTML('<div class="section-heading">Chat</div>')
655
  question = gr.Textbox(
656
  show_label=False,
657
  placeholder="Ask anything you want to research...",
 
702
  )
703
 
704
  with gr.Group(elem_classes="section-card"):
705
+ gr.HTML('<div class="section-heading">Settings</div>')
706
  model = gr.Dropdown(
707
  label="Model",
708
  choices=DEFAULT_FREE_MODELS,