Kesheratmex commited on
Commit
4a1797c
·
1 Parent(s): ac470f2

**Refactor output visibility logic and switch Gradio theme to blue**

Browse files
Files changed (2) hide show
  1. app.py +16 -14
  2. assets/kesheret.css +38 -0
app.py CHANGED
@@ -240,13 +240,7 @@ def _extract_video(d):
240
  def _extract_path(d):
241
  return (d.get("path") if isinstance(d, dict) else d)
242
 
243
- def _extract_video_update(d):
244
- v = (d.get("video") if isinstance(d, dict) else d)
245
- return gr.update(value=v, visible=True)
246
 
247
- def _extract_path_update(d):
248
- v = (d.get("path") if isinstance(d, dict) else d)
249
- return gr.update(value=v, visible=True)
250
 
251
  def _check_token(token: str):
252
  """Token gate for public app. Expected token via env APP_ACCESS_TOKEN or KESHERAT_TOKEN.
@@ -843,21 +837,29 @@ with gr.Blocks(
843
  btn_detect = gr.Button("Detectar defectos", variant="primary")
844
 
845
  # Output section: results appear here after detection
846
- with gr.Row():
847
- with gr.Column():
848
- output_video = gr.Video(label="Vídeo anotado", visible=False)
849
- with gr.Column():
850
- output_image = gr.Image(label="Imagen anotada", visible=False)
851
 
852
  # Hidden JSON components for API chaining
853
  json_video = gr.JSON(visible=False)
854
  json_image = gr.JSON(visible=False)
855
 
856
- # Wire up the detection events
 
 
 
 
 
 
 
 
 
 
 
857
  ev_video = btn_detect.click(fn=infer_media, inputs=video_input, outputs=json_video, api_name="infer_media")
858
- ev_video.then(_extract_video_update, inputs=json_video, outputs=output_video)
859
  ev_image = btn_detect.click(fn=infer_media, inputs=image_input, outputs=json_image, api_name="infer_media_1")
860
- ev_image.then(_extract_path_update, inputs=json_image, outputs=output_image)
861
 
862
  # Wire the gate
863
  btn_enter.click(fn=_check_token, inputs=[gate_token], outputs=[gate_group, app_group, gate_status])
 
240
  def _extract_path(d):
241
  return (d.get("path") if isinstance(d, dict) else d)
242
 
 
 
 
243
 
 
 
 
244
 
245
  def _check_token(token: str):
246
  """Token gate for public app. Expected token via env APP_ACCESS_TOKEN or KESHERAT_TOKEN.
 
837
  btn_detect = gr.Button("Detectar defectos", variant="primary")
838
 
839
  # Output section: results appear here after detection
840
+ output_video = gr.Video(label="Vídeo anotado", visible=False)
841
+ output_image = gr.Image(label="Imagen anotada", visible=False)
 
 
 
842
 
843
  # Hidden JSON components for API chaining
844
  json_video = gr.JSON(visible=False)
845
  json_image = gr.JSON(visible=False)
846
 
847
+ # Functions to show/hide outputs based on active tab and update content
848
+ def _update_video_output(json_result):
849
+ if json_result and json_result.get("output_path"):
850
+ return gr.Video(value=json_result["output_path"], visible=True), gr.Image(visible=False)
851
+ return gr.Video(visible=False), gr.Image(visible=False)
852
+
853
+ def _update_image_output(json_result):
854
+ if json_result and json_result.get("output_path"):
855
+ return gr.Video(visible=False), gr.Image(value=json_result["output_path"], visible=True)
856
+ return gr.Video(visible=False), gr.Image(visible=False)
857
+
858
+ # Wire up the detection events with proper output visibility
859
  ev_video = btn_detect.click(fn=infer_media, inputs=video_input, outputs=json_video, api_name="infer_media")
860
+ ev_video.then(_update_video_output, inputs=json_video, outputs=[output_video, output_image])
861
  ev_image = btn_detect.click(fn=infer_media, inputs=image_input, outputs=json_image, api_name="infer_media_1")
862
+ ev_image.then(_update_image_output, inputs=json_image, outputs=[output_video, output_image])
863
 
864
  # Wire the gate
865
  btn_enter.click(fn=_check_token, inputs=[gate_token], outputs=[gate_group, app_group, gate_status])
assets/kesheret.css CHANGED
@@ -96,5 +96,43 @@ button:hover, .gr-button:hover, .gradio-button:hover {
96
  background: #0056D6 !important;
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
 
 
96
  background: #0056D6 !important;
97
  }
98
 
99
+ /* Override Gradio's purple/violet colors with blue */
100
+ :root {
101
+ --primary-50: #eff6ff !important;
102
+ --primary-100: #dbeafe !important;
103
+ --primary-200: #bfdbfe !important;
104
+ --primary-300: #93c5fd !important;
105
+ --primary-400: #60a5fa !important;
106
+ --primary-500: #0046B8 !important;
107
+ --primary-600: #0046B8 !important;
108
+ --primary-700: #004D85 !important;
109
+ --primary-800: #031F33 !important;
110
+ --primary-900: #031F33 !important;
111
+ }
112
+
113
+ /* Tab headers - force blue instead of purple */
114
+ .gradio-tabs .tab-nav button {
115
+ background: var(--kesheret-blue) !important;
116
+ color: white !important;
117
+ border: none !important;
118
+ }
119
+
120
+ .gradio-tabs .tab-nav button.selected,
121
+ .gradio-tabs .tab-nav button:hover {
122
+ background: var(--medium-blue) !important;
123
+ color: white !important;
124
+ }
125
+
126
+ /* Primary buttons - force blue */
127
+ button[variant="primary"], .primary {
128
+ background: linear-gradient(135deg, var(--kesheret-blue) 0%, var(--medium-blue) 100%) !important;
129
+ color: white !important;
130
+ border: 1px solid var(--kesheret-blue) !important;
131
+ }
132
+
133
+ button[variant="primary"]:hover, .primary:hover {
134
+ background: #0056D6 !important;
135
+ }
136
+
137
  }
138