Spaces:
Sleeping
Sleeping
Fix horizontal scroll - remove Column constraints and add white-space nowrap
Browse files- Remove Column wrappers that constrained HTML component width
- Add width: 100% and white-space: nowrap to container
- Wrap image in inline-block div for proper horizontal scrolling
- HTML components now expand full width with proper scroll in both directions
- Update UI to hint that scrolling is available
app.py
CHANGED
|
@@ -80,23 +80,28 @@ def apply_zoom_output(zoom_level):
|
|
| 80 |
# Convert to base64 for HTML display
|
| 81 |
img_base64 = array_to_base64(zoomed)
|
| 82 |
|
| 83 |
-
# Return HTML with scrollable container
|
| 84 |
html = f"""
|
| 85 |
<div style="
|
| 86 |
border: 1px solid #ccc;
|
| 87 |
border-radius: 4px;
|
| 88 |
overflow: auto;
|
| 89 |
max-height: 600px;
|
|
|
|
| 90 |
padding: 10px;
|
| 91 |
background-color: #f9f9f9;
|
| 92 |
-
|
|
|
|
| 93 |
">
|
| 94 |
-
<
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
</div>
|
| 101 |
<p style="font-size: 12px; color: #666; margin-top: 5px;">
|
| 102 |
Zoom: {zoom_level}% | Size: {new_w}×{new_h}px | Original: {w}×{h}px
|
|
@@ -122,23 +127,28 @@ def apply_zoom_preprocessed(zoom_level):
|
|
| 122 |
# Convert to base64 for HTML display
|
| 123 |
img_base64 = array_to_base64(zoomed)
|
| 124 |
|
| 125 |
-
# Return HTML with scrollable container
|
| 126 |
html = f"""
|
| 127 |
<div style="
|
| 128 |
border: 1px solid #ccc;
|
| 129 |
border-radius: 4px;
|
| 130 |
overflow: auto;
|
| 131 |
max-height: 600px;
|
|
|
|
| 132 |
padding: 10px;
|
| 133 |
background-color: #f9f9f9;
|
| 134 |
-
|
|
|
|
| 135 |
">
|
| 136 |
-
<
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 142 |
</div>
|
| 143 |
<p style="font-size: 12px; color: #666; margin-top: 5px;">
|
| 144 |
Zoom: {zoom_level}% | Size: {new_w}×{new_h}px | Original: {w}×{h}px
|
|
@@ -172,30 +182,33 @@ with gr.Blocks(title="Traffic Sign Detector") as demo:
|
|
| 172 |
detect_btn = gr.Button("Detect Traffic Signs", variant="primary")
|
| 173 |
reset_btn = gr.Button("Clear")
|
| 174 |
|
| 175 |
-
gr.Markdown("### Zoom & Inspect")
|
| 176 |
|
| 177 |
with gr.Row():
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
)
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Auto-detect when image is uploaded
|
| 201 |
input_image.change(
|
|
|
|
| 80 |
# Convert to base64 for HTML display
|
| 81 |
img_base64 = array_to_base64(zoomed)
|
| 82 |
|
| 83 |
+
# Return HTML with scrollable container that allows both directions
|
| 84 |
html = f"""
|
| 85 |
<div style="
|
| 86 |
border: 1px solid #ccc;
|
| 87 |
border-radius: 4px;
|
| 88 |
overflow: auto;
|
| 89 |
max-height: 600px;
|
| 90 |
+
width: 100%;
|
| 91 |
padding: 10px;
|
| 92 |
background-color: #f9f9f9;
|
| 93 |
+
white-space: nowrap;
|
| 94 |
+
box-sizing: border-box;
|
| 95 |
">
|
| 96 |
+
<div style="display: inline-block;">
|
| 97 |
+
<img src="data:image/png;base64,{img_base64}" style="
|
| 98 |
+
width: {new_w}px;
|
| 99 |
+
height: {new_h}px;
|
| 100 |
+
display: block;
|
| 101 |
+
image-rendering: crisp-edges;
|
| 102 |
+
vertical-align: top;
|
| 103 |
+
" />
|
| 104 |
+
</div>
|
| 105 |
</div>
|
| 106 |
<p style="font-size: 12px; color: #666; margin-top: 5px;">
|
| 107 |
Zoom: {zoom_level}% | Size: {new_w}×{new_h}px | Original: {w}×{h}px
|
|
|
|
| 127 |
# Convert to base64 for HTML display
|
| 128 |
img_base64 = array_to_base64(zoomed)
|
| 129 |
|
| 130 |
+
# Return HTML with scrollable container that allows both directions
|
| 131 |
html = f"""
|
| 132 |
<div style="
|
| 133 |
border: 1px solid #ccc;
|
| 134 |
border-radius: 4px;
|
| 135 |
overflow: auto;
|
| 136 |
max-height: 600px;
|
| 137 |
+
width: 100%;
|
| 138 |
padding: 10px;
|
| 139 |
background-color: #f9f9f9;
|
| 140 |
+
white-space: nowrap;
|
| 141 |
+
box-sizing: border-box;
|
| 142 |
">
|
| 143 |
+
<div style="display: inline-block;">
|
| 144 |
+
<img src="data:image/png;base64,{img_base64}" style="
|
| 145 |
+
width: {new_w}px;
|
| 146 |
+
height: {new_h}px;
|
| 147 |
+
display: block;
|
| 148 |
+
image-rendering: crisp-edges;
|
| 149 |
+
vertical-align: top;
|
| 150 |
+
" />
|
| 151 |
+
</div>
|
| 152 |
</div>
|
| 153 |
<p style="font-size: 12px; color: #666; margin-top: 5px;">
|
| 154 |
Zoom: {zoom_level}% | Size: {new_w}×{new_h}px | Original: {w}×{h}px
|
|
|
|
| 182 |
detect_btn = gr.Button("Detect Traffic Signs", variant="primary")
|
| 183 |
reset_btn = gr.Button("Clear")
|
| 184 |
|
| 185 |
+
gr.Markdown("### Zoom & Inspect (Scroll horizontally and vertically as needed)")
|
| 186 |
|
| 187 |
with gr.Row():
|
| 188 |
+
zoom_slider_output = gr.Slider(
|
| 189 |
+
minimum=50,
|
| 190 |
+
maximum=300,
|
| 191 |
+
value=100,
|
| 192 |
+
step=10,
|
| 193 |
+
label="Zoom Detected Image (%)",
|
| 194 |
+
info="Drag to zoom (50% to 300%)",
|
| 195 |
+
scale=1
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
output_html = gr.HTML(label="Zoomed Detected Image")
|
| 199 |
+
|
| 200 |
+
with gr.Row():
|
| 201 |
+
zoom_slider_preprocessed = gr.Slider(
|
| 202 |
+
minimum=50,
|
| 203 |
+
maximum=300,
|
| 204 |
+
value=100,
|
| 205 |
+
step=10,
|
| 206 |
+
label="Zoom Preprocessed Image (%)",
|
| 207 |
+
info="Drag to zoom (50% to 300%)",
|
| 208 |
+
scale=1
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
preprocessed_html = gr.HTML(label="Zoomed Preprocessed Image")
|
| 212 |
|
| 213 |
# Auto-detect when image is uploaded
|
| 214 |
input_image.change(
|