Spaces:
Sleeping
Sleeping
Commit ·
52d4309
1
Parent(s): be1cb53
Add ZIP download button
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ def process_image(
|
|
| 22 |
output_format: str,
|
| 23 |
):
|
| 24 |
if not image_path:
|
| 25 |
-
return None, "<span>No image loaded</span>", [], None
|
| 26 |
|
| 27 |
run_dir = Path(tempfile.mkdtemp(prefix="run-", dir=WORK_ROOT))
|
| 28 |
image = read_image(image_path)
|
|
@@ -34,7 +34,7 @@ def process_image(
|
|
| 34 |
)
|
| 35 |
|
| 36 |
if not result.regions:
|
| 37 |
-
return None, "<span>No frames detected</span>", [], None
|
| 38 |
|
| 39 |
annotated = annotate_regions(image, result.regions)
|
| 40 |
annotated_path = run_dir / "detected-grid.jpg"
|
|
@@ -63,11 +63,11 @@ def process_image(
|
|
| 63 |
f"<span>{len(result.regions)} frames extracted from "
|
| 64 |
f"{result.columns} columns x {result.rows} rows</span>"
|
| 65 |
)
|
| 66 |
-
return str(annotated_path), status, frame_paths, str(zip_path)
|
| 67 |
|
| 68 |
|
| 69 |
def clear_outputs():
|
| 70 |
-
return None, "<span>No image loaded</span>", [], None
|
| 71 |
|
| 72 |
|
| 73 |
def extension_for_format(output_format: str) -> str:
|
|
@@ -145,6 +145,11 @@ def build_app() -> gr.Blocks:
|
|
| 145 |
)
|
| 146 |
extract_button = gr.Button("Extract", variant="primary")
|
| 147 |
zip_file = gr.File(label="Download ZIP", elem_classes="zip-download")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
with gr.Column(elem_classes="frames-section"):
|
| 150 |
gr.HTML("<div class='section-head'><h2>Extracted frames</h2></div>")
|
|
@@ -164,7 +169,7 @@ def build_app() -> gr.Blocks:
|
|
| 164 |
separator_mode,
|
| 165 |
output_format,
|
| 166 |
]
|
| 167 |
-
extract_outputs = [annotated_image, status, gallery, zip_file]
|
| 168 |
|
| 169 |
input_image.upload(process_image, extract_inputs, extract_outputs)
|
| 170 |
extract_button.click(process_image, extract_inputs, extract_outputs)
|
|
@@ -284,6 +289,10 @@ button.primary,
|
|
| 284 |
background: #d7efea !important;
|
| 285 |
}
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
.frames-section {
|
| 288 |
margin: 28px auto 0 !important;
|
| 289 |
max-width: 1440px !important;
|
|
|
|
| 22 |
output_format: str,
|
| 23 |
):
|
| 24 |
if not image_path:
|
| 25 |
+
return None, "<span>No image loaded</span>", [], None, None
|
| 26 |
|
| 27 |
run_dir = Path(tempfile.mkdtemp(prefix="run-", dir=WORK_ROOT))
|
| 28 |
image = read_image(image_path)
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
if not result.regions:
|
| 37 |
+
return None, "<span>No frames detected</span>", [], None, None
|
| 38 |
|
| 39 |
annotated = annotate_regions(image, result.regions)
|
| 40 |
annotated_path = run_dir / "detected-grid.jpg"
|
|
|
|
| 63 |
f"<span>{len(result.regions)} frames extracted from "
|
| 64 |
f"{result.columns} columns x {result.rows} rows</span>"
|
| 65 |
)
|
| 66 |
+
return str(annotated_path), status, frame_paths, str(zip_path), str(zip_path)
|
| 67 |
|
| 68 |
|
| 69 |
def clear_outputs():
|
| 70 |
+
return None, "<span>No image loaded</span>", [], None, None
|
| 71 |
|
| 72 |
|
| 73 |
def extension_for_format(output_format: str) -> str:
|
|
|
|
| 145 |
)
|
| 146 |
extract_button = gr.Button("Extract", variant="primary")
|
| 147 |
zip_file = gr.File(label="Download ZIP", elem_classes="zip-download")
|
| 148 |
+
zip_button = gr.DownloadButton(
|
| 149 |
+
"Download all frames",
|
| 150 |
+
variant="primary",
|
| 151 |
+
elem_classes="zip-button",
|
| 152 |
+
)
|
| 153 |
|
| 154 |
with gr.Column(elem_classes="frames-section"):
|
| 155 |
gr.HTML("<div class='section-head'><h2>Extracted frames</h2></div>")
|
|
|
|
| 169 |
separator_mode,
|
| 170 |
output_format,
|
| 171 |
]
|
| 172 |
+
extract_outputs = [annotated_image, status, gallery, zip_file, zip_button]
|
| 173 |
|
| 174 |
input_image.upload(process_image, extract_inputs, extract_outputs)
|
| 175 |
extract_button.click(process_image, extract_inputs, extract_outputs)
|
|
|
|
| 289 |
background: #d7efea !important;
|
| 290 |
}
|
| 291 |
|
| 292 |
+
.zip-button {
|
| 293 |
+
width: 100% !important;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
.frames-section {
|
| 297 |
margin: 28px auto 0 !important;
|
| 298 |
max-width: 1440px !important;
|