Roman190928 commited on
Commit
eac34f8
·
verified ·
1 Parent(s): 26d89a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -42,6 +42,9 @@ body { background: var(--bg); color:var(--text); font-family: Inter, system-ui,
42
 
43
  /* minor Gradio element tweaks */
44
  input[type="number"], .gradio-number { background: transparent; color: var(--text); border-radius:6px; }
 
 
 
45
  """
46
 
47
  # ------------------------
@@ -109,20 +112,18 @@ def preset_tf_for_ui(selected_gpu: str, dtype: str):
109
  return GPUS[selected_gpu].get(dtype, 0.0)
110
  return 0.0
111
 
112
- # ------------------------
113
- # Theme setter (returns HTML snippet to run client-side JS)
114
- # ------------------------
115
- def set_theme(theme_name: str):
116
- cls = {
117
- "Blue": "theme-blue",
118
- "Green": "theme-green",
119
- "Purple": "theme-purple",
120
- }.get(theme_name, "theme-blue")
121
- return f"<script>document.documentElement.className='{cls}';</script>"
122
-
123
  # ------------------------
124
  # Build UI
125
  # ------------------------
 
 
 
 
 
 
 
 
 
126
  with gr.Blocks() as demo:
127
  # initial theme set (runs immediately on load)
128
  gr.HTML("<script>document.documentElement.className='theme-blue';</script>")
@@ -130,10 +131,8 @@ with gr.Blocks() as demo:
130
  with gr.Column(elem_classes="card"):
131
  with gr.Row():
132
  gr.Markdown("## 🧠 Roman’s Training Time Estimator")
133
- with gr.Row():
134
- btn_blue = gr.Button("Blue", elem_classes="btn-theme")
135
- btn_green = gr.Button("Green", elem_classes="btn-theme")
136
- btn_purple = gr.Button("Purple", elem_classes="btn-theme")
137
 
138
  with gr.Column(elem_classes="card"):
139
  gr.Markdown("### Model & Hardware")
@@ -152,9 +151,6 @@ with gr.Blocks() as demo:
152
  result = gr.Textbox(lines=12, interactive=False, elem_classes="result-box", label="Result")
153
  run_btn = gr.Button("Estimate Training Time", elem_classes="btn-theme")
154
 
155
- # invisible HTML target used to inject theme-changing script
156
- theme_script = gr.HTML(value="")
157
-
158
  # update TF override when gpu/dtype change
159
  def _update_tf(selected_gpu, dtype):
160
  return gr.update(value=preset_tf_for_ui(selected_gpu, dtype))
@@ -166,13 +162,8 @@ with gr.Blocks() as demo:
166
  inputs=[params, tokens, gpu_dropdown, dtype_dropdown, tf_override, utilization],
167
  outputs=[result])
168
 
169
- # THE FIXED THEME BUTTONS: use zero-arg lambdas that return the HTML script value
170
- btn_blue.click(lambda: set_theme("Blue"), outputs=[theme_script])
171
- btn_green.click(lambda: set_theme("Green"), outputs=[theme_script])
172
- btn_purple.click(lambda: set_theme("Purple"), outputs=[theme_script])
173
-
174
  gr.HTML("<div class='small-muted'>Tip: GPU presets are TFLOPs per dtype. You can edit the TFLOPs number to override. Utilization reduces theoretical peak to realistic throughput.</div>")
175
 
176
- # pass CSS to launch (Gradio 6.0+ API)
177
  if __name__ == "__main__":
178
  demo.launch(css=CSS)
 
42
 
43
  /* minor Gradio element tweaks */
44
  input[type="number"], .gradio-number { background: transparent; color: var(--text); border-radius:6px; }
45
+
46
+ /* theme button row */
47
+ .theme-btn-row { display:flex; gap:8px; align-items:center; }
48
  """
49
 
50
  # ------------------------
 
112
  return GPUS[selected_gpu].get(dtype, 0.0)
113
  return 0.0
114
 
 
 
 
 
 
 
 
 
 
 
 
115
  # ------------------------
116
  # Build UI
117
  # ------------------------
118
+ # Inline HTML for theme buttons with client-side onclick handlers
119
+ THEME_BUTTONS_HTML = """
120
+ <div class="theme-btn-row">
121
+ <button class="btn-theme" onclick="document.documentElement.className='theme-blue'">Blue</button>
122
+ <button class="btn-theme" onclick="document.documentElement.className='theme-green'">Green</button>
123
+ <button class="btn-theme" onclick="document.documentElement.className='theme-purple'">Purple</button>
124
+ </div>
125
+ """
126
+
127
  with gr.Blocks() as demo:
128
  # initial theme set (runs immediately on load)
129
  gr.HTML("<script>document.documentElement.className='theme-blue';</script>")
 
131
  with gr.Column(elem_classes="card"):
132
  with gr.Row():
133
  gr.Markdown("## 🧠 Roman’s Training Time Estimator")
134
+ # render the theme buttons as raw HTML so onclick works client-side instantly
135
+ gr.HTML(THEME_BUTTONS_HTML)
 
 
136
 
137
  with gr.Column(elem_classes="card"):
138
  gr.Markdown("### Model & Hardware")
 
151
  result = gr.Textbox(lines=12, interactive=False, elem_classes="result-box", label="Result")
152
  run_btn = gr.Button("Estimate Training Time", elem_classes="btn-theme")
153
 
 
 
 
154
  # update TF override when gpu/dtype change
155
  def _update_tf(selected_gpu, dtype):
156
  return gr.update(value=preset_tf_for_ui(selected_gpu, dtype))
 
162
  inputs=[params, tokens, gpu_dropdown, dtype_dropdown, tf_override, utilization],
163
  outputs=[result])
164
 
 
 
 
 
 
165
  gr.HTML("<div class='small-muted'>Tip: GPU presets are TFLOPs per dtype. You can edit the TFLOPs number to override. Utilization reduces theoretical peak to realistic throughput.</div>")
166
 
167
+ # pass CSS to launch
168
  if __name__ == "__main__":
169
  demo.launch(css=CSS)