Spaces:
Running on Zero
Running on Zero
Show cropped regions with preserved aspect ratio and dimensions
Browse files
app.py
CHANGED
|
@@ -1153,7 +1153,14 @@ def _draw_selected_region_boxes(image, boxes):
|
|
| 1153 |
return img_out
|
| 1154 |
|
| 1155 |
def _region_gallery_items(regions):
|
| 1156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1157 |
|
| 1158 |
def _label_gallery_items(items, prefix=None):
|
| 1159 |
labeled = []
|
|
@@ -1164,6 +1171,8 @@ def _label_gallery_items(items, prefix=None):
|
|
| 1164 |
img, label = item, f"Item {i}"
|
| 1165 |
if prefix:
|
| 1166 |
label = f"{prefix} - {label}"
|
|
|
|
|
|
|
| 1167 |
labeled.append((img, label))
|
| 1168 |
return labeled
|
| 1169 |
|
|
@@ -1392,7 +1401,14 @@ with gr.Blocks(title="DeepSeek-OCR-2") as demo:
|
|
| 1392 |
add_region_btn = gr.Button("Add Region", variant="secondary")
|
| 1393 |
clear_regions_btn = gr.Button("Clear Regions")
|
| 1394 |
selection_status = gr.Textbox(label="Region Selection Status", value="No saved regions.", interactive=False, visible=False)
|
| 1395 |
-
selected_regions_gallery = gr.Gallery(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1396 |
|
| 1397 |
with gr.Accordion("Advanced Options", open=False):
|
| 1398 |
equation_zoom = gr.Checkbox(label="Equation Zoom (multipass)", value=False)
|
|
@@ -1410,7 +1426,7 @@ with gr.Blocks(title="DeepSeek-OCR-2") as demo:
|
|
| 1410 |
with gr.Tab("Boxes", id="tab_boxes"):
|
| 1411 |
img_out = gr.Image(type="pil", height=560, show_label=False)
|
| 1412 |
with gr.Tab("Cropped Images", id="tab_crops"):
|
| 1413 |
-
gallery = gr.Gallery(show_label=False, columns=3, height=420)
|
| 1414 |
with gr.Tab("Raw Text", id="tab_raw"):
|
| 1415 |
raw_out = gr.Textbox(lines=20, buttons=["copy"], show_label=False)
|
| 1416 |
download_btn = gr.DownloadButton("Download Markdown", visible=False, variant="secondary")
|
|
|
|
| 1153 |
return img_out
|
| 1154 |
|
| 1155 |
def _region_gallery_items(regions):
|
| 1156 |
+
items = []
|
| 1157 |
+
for i, r in enumerate(regions, 1):
|
| 1158 |
+
img = r["image"]
|
| 1159 |
+
label = f"Region {i}"
|
| 1160 |
+
if isinstance(img, Image.Image):
|
| 1161 |
+
label = f"{label} ({img.width}x{img.height})"
|
| 1162 |
+
items.append((img, label))
|
| 1163 |
+
return items
|
| 1164 |
|
| 1165 |
def _label_gallery_items(items, prefix=None):
|
| 1166 |
labeled = []
|
|
|
|
| 1171 |
img, label = item, f"Item {i}"
|
| 1172 |
if prefix:
|
| 1173 |
label = f"{prefix} - {label}"
|
| 1174 |
+
if isinstance(img, Image.Image):
|
| 1175 |
+
label = f"{label} ({img.width}x{img.height})"
|
| 1176 |
labeled.append((img, label))
|
| 1177 |
return labeled
|
| 1178 |
|
|
|
|
| 1401 |
add_region_btn = gr.Button("Add Region", variant="secondary")
|
| 1402 |
clear_regions_btn = gr.Button("Clear Regions")
|
| 1403 |
selection_status = gr.Textbox(label="Region Selection Status", value="No saved regions.", interactive=False, visible=False)
|
| 1404 |
+
selected_regions_gallery = gr.Gallery(
|
| 1405 |
+
label="Selected Regions",
|
| 1406 |
+
show_label=True,
|
| 1407 |
+
columns=2,
|
| 1408 |
+
height=190,
|
| 1409 |
+
visible=False,
|
| 1410 |
+
object_fit="contain",
|
| 1411 |
+
)
|
| 1412 |
|
| 1413 |
with gr.Accordion("Advanced Options", open=False):
|
| 1414 |
equation_zoom = gr.Checkbox(label="Equation Zoom (multipass)", value=False)
|
|
|
|
| 1426 |
with gr.Tab("Boxes", id="tab_boxes"):
|
| 1427 |
img_out = gr.Image(type="pil", height=560, show_label=False)
|
| 1428 |
with gr.Tab("Cropped Images", id="tab_crops"):
|
| 1429 |
+
gallery = gr.Gallery(show_label=False, columns=3, height=420, object_fit="contain")
|
| 1430 |
with gr.Tab("Raw Text", id="tab_raw"):
|
| 1431 |
raw_out = gr.Textbox(lines=20, buttons=["copy"], show_label=False)
|
| 1432 |
download_btn = gr.DownloadButton("Download Markdown", visible=False, variant="secondary")
|