Update app.py
Browse files
app.py
CHANGED
|
@@ -109,6 +109,7 @@ def sample_paths(paths: List[Path] | List[str], n: int = 30) -> List[str]:
|
|
| 109 |
|
| 110 |
import base64
|
| 111 |
|
|
|
|
| 112 |
def load_logo_base64(path: str) -> str:
|
| 113 |
with open(path, "rb") as f:
|
| 114 |
return base64.b64encode(f.read()).decode("utf-8")
|
|
@@ -353,7 +354,21 @@ def build_ffmpeg_extract(
|
|
| 353 |
return cmd
|
| 354 |
|
| 355 |
frames = sorted(raw_dir.glob(f"{prefix}_*.{out_format}"), key=_natural_key)
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
def realesrgan(img, model_name, denoise_strength, face_enhance, outscale):
|
| 359 |
if img is None:
|
|
@@ -555,7 +570,7 @@ def step1_extract(
|
|
| 555 |
|
| 556 |
frames = sorted(raw_dir.glob(f"{prefix}_*.{out_format}"), key=_natural_key)
|
| 557 |
|
| 558 |
-
|
| 559 |
zip_path = work / "frames.zip"
|
| 560 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 561 |
for p in frames:
|
|
@@ -1039,7 +1054,7 @@ def build_ui():
|
|
| 1039 |
with gr.Row():
|
| 1040 |
btn_extract = gr.Button("Step 1: Extract Frames", variant="primary")
|
| 1041 |
prog1 = gr.HTML(render_progress(0.0, "Idle"))
|
| 1042 |
-
gallery = gr.Gallery(label="Preview (
|
| 1043 |
zip_out = gr.File(label="Download frames ZIP")
|
| 1044 |
details1 = gr.Markdown("Ready.")
|
| 1045 |
with gr.Accordion("Show FFmpeg command", open=False):
|
|
|
|
| 109 |
|
| 110 |
import base64
|
| 111 |
|
| 112 |
+
APP_DIR = os.getcwd()
|
| 113 |
def load_logo_base64(path: str) -> str:
|
| 114 |
with open(path, "rb") as f:
|
| 115 |
return base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
| 354 |
return cmd
|
| 355 |
|
| 356 |
frames = sorted(raw_dir.glob(f"{prefix}_*.{out_format}"), key=_natural_key)
|
| 357 |
+
|
| 358 |
+
# Adaptive preview:
|
| 359 |
+
if len(frames) <= 100:
|
| 360 |
+
gallery = [str(p) for p in frames] # show all
|
| 361 |
+
else:
|
| 362 |
+
gallery = sample_paths(frames, 100) # evenly sample 100
|
| 363 |
+
|
| 364 |
+
zip_path = work / "frames.zip"
|
| 365 |
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 366 |
+
for p in frames:
|
| 367 |
+
zf.write(p, p.name)
|
| 368 |
+
|
| 369 |
+
details = f"Frames extracted: {len(frames)} | Saved to: {raw_dir}"
|
| 370 |
+
return gallery, str(zip_path), details, cmd_preview, render_progress(100.0, f"Extracted {len(frames)} frames"), [str(p) for p in frames], str(raw_dir), prefix
|
| 371 |
+
|
| 372 |
|
| 373 |
def realesrgan(img, model_name, denoise_strength, face_enhance, outscale):
|
| 374 |
if img is None:
|
|
|
|
| 570 |
|
| 571 |
frames = sorted(raw_dir.glob(f"{prefix}_*.{out_format}"), key=_natural_key)
|
| 572 |
|
| 573 |
+
[str(p) for p in frames] # show all extracted frames
|
| 574 |
zip_path = work / "frames.zip"
|
| 575 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 576 |
for p in frames:
|
|
|
|
| 1054 |
with gr.Row():
|
| 1055 |
btn_extract = gr.Button("Step 1: Extract Frames", variant="primary")
|
| 1056 |
prog1 = gr.HTML(render_progress(0.0, "Idle"))
|
| 1057 |
+
gallery = gr.Gallery(label="Preview (all ≤100, else sample 100)", columns=6, height=480)
|
| 1058 |
zip_out = gr.File(label="Download frames ZIP")
|
| 1059 |
details1 = gr.Markdown("Ready.")
|
| 1060 |
with gr.Accordion("Show FFmpeg command", open=False):
|