Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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 |
-
/*
|
| 271 |
-
.legend-
|
|
|
|
|
|
|
| 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 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 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 |
-
|
| 308 |
for i, name in enumerate(_classes):
|
| 309 |
color = _FIXED_PALETTE[i] if i < len(_FIXED_PALETTE) else [128, 128, 128]
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
return "<div>"+"".join(
|
| 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):
|