triton7777 commited on
Commit
01d2a9d
·
verified ·
1 Parent(s): 9cdea18

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -259,7 +259,7 @@ def predict(image: np.ndarray):
259
 
260
  SEA_CSS = """
261
  body, .gradio-container { background: linear-gradient(180deg, #e7f3fb 0%, #d9eef9 60%, #cfe8f5 100%) !important; }
262
- .gradio-container { max-width: 1100px; margin: 0 auto; }
263
  .gr-block { gap: 8px; }
264
  .title { color: #0b3d59; }
265
  /* Compact slider styling */
@@ -267,8 +267,10 @@ body, .gradio-container { background: linear-gradient(180deg, #e7f3fb 0%, #d9eef
267
  .compact-slider .wrap { padding: 0 !important; }
268
  /* Remove component box chrome where undesired */
269
  .no-box .gr-box { box-shadow: none !important; border: none !important; background: transparent !important; padding: 0 !important; }
270
- /* Compact legend styling */
271
- .legend-box { width: 220px; max-height: 480px; overflow: auto; background: transparent; border: none; padding: 4px 4px; }
 
 
272
  """
273
 
274
  with gr.Blocks(css=SEA_CSS) as demo:
@@ -287,14 +289,14 @@ with gr.Blocks(css=SEA_CSS) as demo:
287
  example_paths = []
288
 
289
  with gr.Row():
290
- inp = gr.Image(type="numpy", label="Input image", height=320)
291
- mix = gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="Segmentation mix (0=image, 1=seg)", elem_classes=["compact-slider", "no-box"])
292
- if example_paths:
293
- gr.Examples(examples=example_paths, inputs=inp, label="Examples from ./images")
294
-
295
- with gr.Row():
296
- out = gr.Image(type="numpy", label="Segmentation overlay", height=512)
297
- legend = gr.HTML(value="", elem_classes=["legend-box", "no-box"])
298
  btn = gr.Button("Segment")
299
 
300
  # Hold last input image and segmentation RGB to re-blend without re-inference
@@ -304,13 +306,13 @@ with gr.Blocks(css=SEA_CSS) as demo:
304
  info = gr.Markdown(value="")
305
  # Legend
306
  def _legend_html():
307
- rows = []
308
  for i, name in enumerate(_classes):
309
  color = _FIXED_PALETTE[i] if i < len(_FIXED_PALETTE) else [128, 128, 128]
310
- rows.append(f'<div style="display:flex;align-items:center;gap:8px;margin:2px 0;">'
311
- f'<span style="display:inline-block;width:14px;height:14px;background:rgb({color[0]},{color[1]},{color[2]});border:1px solid #333"></span>'
312
- f'<span style="font-size:12px;">{i}: {name}</span></div>')
313
- return "<div>"+"".join(rows)+"</div>"
314
  legend.value = _legend_html()
315
 
316
  def _predict_with_alpha(img, s_mix):
 
259
 
260
  SEA_CSS = """
261
  body, .gradio-container { background: linear-gradient(180deg, #e7f3fb 0%, #d9eef9 60%, #cfe8f5 100%) !important; }
262
+ .gradio-container { max-width: 1100px; margin: 0 auto; color: #111; }
263
  .gr-block { gap: 8px; }
264
  .title { color: #0b3d59; }
265
  /* Compact slider styling */
 
267
  .compact-slider .wrap { padding: 0 !important; }
268
  /* Remove component box chrome where undesired */
269
  .no-box .gr-box { box-shadow: none !important; border: none !important; background: transparent !important; padding: 0 !important; }
270
+ /* Horizontal legend styling */
271
+ .legend-row { width: 100%; padding: 4px 0; }
272
+ .legend-row .legend-item { display: inline-flex; align-items: center; gap: 6px; margin: 2px 8px 2px 0; color: #111; font-size: 12px; }
273
+ .legend-row .chip { display: inline-block; width: 14px; height: 14px; border: 1px solid #333; }
274
  """
275
 
276
  with gr.Blocks(css=SEA_CSS) as demo:
 
289
  example_paths = []
290
 
291
  with gr.Row():
292
+ with gr.Column(scale=6):
293
+ inp = gr.Image(type="numpy", label="Input image", height=380)
294
+ if example_paths:
295
+ gr.Examples(examples=example_paths, inputs=inp, label="Examples from ./images")
296
+ mix = gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="Segmentation mix (0=image, 1=seg)", elem_classes=["compact-slider", "no-box"])
297
+ with gr.Column(scale=6):
298
+ out = gr.Image(type="numpy", label="Segmentation overlay", height=512)
299
+ legend = gr.HTML(value="", elem_classes=["legend-row", "no-box"])
300
  btn = gr.Button("Segment")
301
 
302
  # Hold last input image and segmentation RGB to re-blend without re-inference
 
306
  info = gr.Markdown(value="")
307
  # Legend
308
  def _legend_html():
309
+ items = []
310
  for i, name in enumerate(_classes):
311
  color = _FIXED_PALETTE[i] if i < len(_FIXED_PALETTE) else [128, 128, 128]
312
+ items.append(
313
+ f'<span class="legend-item"><span class="chip" style="background:rgb({color[0]},{color[1]},{color[2]})"></span>{i}: {name}</span>'
314
+ )
315
+ return "<div class=\"legend-row\">"+"".join(items)+"</div>"
316
  legend.value = _legend_html()
317
 
318
  def _predict_with_alpha(img, s_mix):