PeterPinetree commited on
Commit
35d29d6
·
1 Parent(s): a097df3

Enhance UI styling and layout for Next-Token Predictor with gradient backgrounds, improved button designs, and updated tooltip functionality

Browse files
Files changed (1) hide show
  1. app.py +138 -50
app.py CHANGED
@@ -119,38 +119,80 @@ def create_clickable_token_display(tokens_data: List[Dict]) -> str:
119
 
120
  return html
121
 
122
- # Custom CSS to match the original design
123
  custom_css = """
 
124
  .gradio-container {
125
- background: #0b1220 !important;
126
- color: #e6f1ff !important;
 
127
  }
128
 
 
129
  .block {
130
- background: #0e162b !important;
131
- border: 1px solid #1c2945 !important;
132
- border-radius: 14px !important;
 
133
  }
134
 
 
135
  .tab-item {
136
- background: #0e1629 !important;
137
- border: 1px solid #1c2945 !important;
 
138
  }
139
 
 
140
  .token-button {
141
- background: #0f1930 !important;
142
- border: 1px solid #22365e !important;
143
- color: #e6f1ff !important;
144
- border-radius: 6px !important;
145
  margin: 0px !important;
146
- padding: 2px 6px !important;
147
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
148
- transition: background 0.2s !important;
149
  font-size: 12px !important;
 
150
  }
151
 
152
  .token-button:hover {
153
- background: #1a2b4a !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  /* Remove Gradio's default spacing between buttons */
@@ -167,77 +209,123 @@ div:has(> .token-button) {
167
  .block > div > div {
168
  gap: 0px !important;
169
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  """
171
 
172
  # Create Gradio interface
173
  with gr.Blocks(css=custom_css, title="Next-Token Predictor") as app:
174
  gr.HTML("""
175
- <div style="text-align: center; padding: 20px; background: #0e1629; border-bottom: 1px solid #1c2945;">
176
- <h1 style="color: #e6f1ff; margin: 0; font-size: 24px;">🤗 Next-Token Predictor</h1>
177
- <p style="color: #9ab0d0; margin: 10px 0 0 0;">Explore how AI predicts the next word! Click on predictions to append them.</p>
178
  </div>
179
  """)
180
 
181
- with gr.Row():
182
- with gr.Column(scale=1):
183
- text_input = gr.Textbox(
184
- label="Enter your prompt:",
185
- placeholder="Type anything... predictions update automatically!",
186
- value="Twinkle, twinkle, little ",
187
- lines=3,
188
- info="💡 Try: 'The weather today is', 'I think that', 'Once upon a time'"
189
- )
 
 
 
190
 
191
- with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  top_k = gr.Slider(
193
  minimum=5,
194
  maximum=15,
195
  value=10,
196
  step=1,
197
  label="Top-K",
198
- info="How many top predictions to show",
199
  show_label=True,
200
  interactive=True
201
  )
 
 
202
  temperature = gr.Slider(
203
  minimum=0.1,
204
  maximum=2.0,
205
  value=1.0,
206
  step=0.1,
207
- label="Temperature",
208
- info="Creativity: Low=predictable, High=surprising",
209
  show_label=True,
210
  interactive=True
211
  )
 
 
212
  top_p = gr.Slider(
213
  minimum=0.1,
214
  maximum=1.0,
215
  value=0.9,
216
  step=0.05,
217
  label="Top-P",
218
- info="Consider words making up this % of probability",
219
  show_label=True,
220
  interactive=True
221
  )
222
-
223
- timing_info = gr.HTML(value="<div style='color: #9ab0d0; font-size: 12px;'>✨ Predictions update as you type!</div>")
224
 
225
- with gr.Column(scale=1):
226
- # Create a column for token buttons
227
- with gr.Column():
228
- gr.HTML("<h4 style='color: #e6f1ff; margin: 0;'>🔮 Next Token Predictions</h4>")
229
-
230
- # Create buttons for each possible token (we'll show/hide as needed)
231
- token_buttons = []
232
- for i in range(15): # Support up to 15 tokens
233
- btn = gr.Button(
234
- value="",
235
- visible=False,
236
- elem_classes=["token-button"],
237
- size="sm"
238
- )
239
- token_buttons.append(btn)
240
-
241
  # Store current tokens data
242
  current_tokens = gr.State([])
243
 
 
119
 
120
  return html
121
 
122
+ # Custom CSS to match the Token Visualizer gradient color scheme
123
  custom_css = """
124
+ /* Main container with gradient background like Token Visualizer */
125
  .gradio-container {
126
+ background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%) !important;
127
+ color: #e2e8f0 !important;
128
+ min-height: 100vh !important;
129
  }
130
 
131
+ /* Blocks with subtle transparency and borders */
132
  .block {
133
+ background: rgba(15, 23, 42, 0.8) !important;
134
+ border: 1px solid rgba(148, 163, 184, 0.2) !important;
135
+ border-radius: 12px !important;
136
+ backdrop-filter: blur(8px) !important;
137
  }
138
 
139
+ /* Tab styling */
140
  .tab-item {
141
+ background: rgba(30, 41, 59, 0.6) !important;
142
+ border: 1px solid rgba(148, 163, 184, 0.2) !important;
143
+ border-radius: 8px !important;
144
  }
145
 
146
+ /* Token buttons with modern gradient and hover effects */
147
  .token-button {
148
+ background: linear-gradient(135deg, #1e293b 0%, #334155 100%) !important;
149
+ border: 1px solid rgba(148, 163, 184, 0.3) !important;
150
+ color: #e2e8f0 !important;
151
+ border-radius: 8px !important;
152
  margin: 0px !important;
153
+ padding: 3px 8px !important;
154
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
155
+ transition: all 0.3s ease !important;
156
  font-size: 12px !important;
157
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
158
  }
159
 
160
  .token-button:hover {
161
+ background: linear-gradient(135deg, #334155 0%, #475569 100%) !important;
162
+ border-color: rgba(148, 163, 184, 0.5) !important;
163
+ transform: translateY(-1px) !important;
164
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4) !important;
165
+ }
166
+
167
+ /* Input fields styling */
168
+ .gr-textbox {
169
+ background: rgba(30, 41, 59, 0.6) !important;
170
+ border: 1px solid rgba(148, 163, 184, 0.3) !important;
171
+ border-radius: 8px !important;
172
+ color: #e2e8f0 !important;
173
+ }
174
+
175
+ /* Slider styling */
176
+ .gr-slider {
177
+ background: rgba(30, 41, 59, 0.6) !important;
178
+ }
179
+
180
+ .gr-slider input[type="range"] {
181
+ background: linear-gradient(to right, #3b82f6, #06b6d4) !important;
182
+ }
183
+
184
+ /* Labels and text */
185
+ .gr-label {
186
+ color: #cbd5e1 !important;
187
+ font-weight: 500 !important;
188
+ }
189
+
190
+ .gr-info {
191
+ color: #94a3b8 !important;
192
+ background: rgba(30, 41, 59, 0.4) !important;
193
+ border-radius: 6px !important;
194
+ padding: 4px 8px !important;
195
+ border: 1px solid rgba(148, 163, 184, 0.2) !important;
196
  }
197
 
198
  /* Remove Gradio's default spacing between buttons */
 
209
  .block > div > div {
210
  gap: 0px !important;
211
  }
212
+
213
+ /* Hide spinner arrows on number inputs */
214
+ input[type="number"]::-webkit-outer-spin-button,
215
+ input[type="number"]::-webkit-inner-spin-button {
216
+ -webkit-appearance: none !important;
217
+ margin: 0 !important;
218
+ }
219
+
220
+ input[type="number"] {
221
+ -moz-appearance: textfield !important;
222
+ }
223
+
224
+ /* Header styling to match Token Visualizer */
225
+ h1, h2, h3, h4 {
226
+ background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%) !important;
227
+ -webkit-background-clip: text !important;
228
+ -webkit-text-fill-color: transparent !important;
229
+ background-clip: text !important;
230
+ }
231
+
232
+ /* Interactive tooltip icons in labels */
233
+ .gr-label {
234
+ position: relative !important;
235
+ }
236
+
237
+ /* Add tooltip functionality with JavaScript */
238
+ .gr-label:has-text("ⓘ"):hover::after {
239
+ content: attr(data-tooltip);
240
+ position: absolute;
241
+ background: rgba(15, 23, 42, 0.95);
242
+ color: #e2e8f0;
243
+ padding: 8px 12px;
244
+ border-radius: 6px;
245
+ font-size: 12px;
246
+ max-width: 250px;
247
+ border: 1px solid rgba(148, 163, 184, 0.3);
248
+ z-index: 1000;
249
+ top: 100%;
250
+ left: 0;
251
+ margin-top: 5px;
252
+ white-space: pre-wrap;
253
+ }
254
  """
255
 
256
  # Create Gradio interface
257
  with gr.Blocks(css=custom_css, title="Next-Token Predictor") as app:
258
  gr.HTML("""
259
+ <div style="text-align: center; padding: 32px 20px; background: linear-gradient(135deg, rgba(15, 23, 42, 0.9) 0%, rgba(30, 41, 59, 0.9) 50%, rgba(15, 23, 42, 0.9) 100%); border-bottom: 1px solid rgba(148, 163, 184, 0.2); backdrop-filter: blur(8px);">
260
+ <h1 style="background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin: 0; font-size: 28px; font-weight: 600;">Next-Token Predictor</h1>
261
+ <p style="color: #94a3b8; margin: 12px 0 0 0; font-size: 16px; opacity: 0.9;">Explore how AI predicts the next word! Click on predictions to append them.</p>
262
  </div>
263
  """)
264
 
265
+ with gr.Column():
266
+ text_input = gr.Textbox(
267
+ label="Enter your prompt:",
268
+ placeholder="Type anything... predictions update automatically!",
269
+ value="Twinkle, twinkle, little ",
270
+ lines=3,
271
+ info="💡 Try: 'The weather today is', 'I think that', 'Once upon a time'"
272
+ )
273
+
274
+ # Next Token Predictions directly below input
275
+ with gr.Column():
276
+ gr.HTML("<h4 style='background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin: 0; font-weight: 600;'>Next Token Predictions</h4>")
277
 
278
+ # Create buttons for each possible token (we'll show/hide as needed)
279
+ token_buttons = []
280
+ for i in range(15): # Support up to 15 tokens
281
+ btn = gr.Button(
282
+ value="",
283
+ visible=False,
284
+ elem_classes=["token-button"],
285
+ size="sm"
286
+ )
287
+ token_buttons.append(btn)
288
+
289
+ # Parameter controls below predictions
290
+ with gr.Row():
291
+ with gr.Column():
292
  top_k = gr.Slider(
293
  minimum=5,
294
  maximum=15,
295
  value=10,
296
  step=1,
297
  label="Top-K",
298
+ info="Number of most likely words to consider",
299
  show_label=True,
300
  interactive=True
301
  )
302
+
303
+ with gr.Column():
304
  temperature = gr.Slider(
305
  minimum=0.1,
306
  maximum=2.0,
307
  value=1.0,
308
  step=0.1,
309
+ label="Temperature",
310
+ info="Controls randomness in predictions",
311
  show_label=True,
312
  interactive=True
313
  )
314
+
315
+ with gr.Column():
316
  top_p = gr.Slider(
317
  minimum=0.1,
318
  maximum=1.0,
319
  value=0.9,
320
  step=0.05,
321
  label="Top-P",
322
+ info="Probability threshold for word selection",
323
  show_label=True,
324
  interactive=True
325
  )
 
 
326
 
327
+ timing_info = gr.HTML(value="<div style='color: #94a3b8; font-size: 12px; opacity: 0.8;'>✨ Predictions update as you type!</div>")
328
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  # Store current tokens data
330
  current_tokens = gr.State([])
331