Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -29,18 +29,16 @@ from inference.loading import ModelPaths # noqa: E402
|
|
| 29 |
from inference.pipeline import build_inference_pipeline # noqa: E402
|
| 30 |
from inference.request import InferenceRequest # noqa: E402
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
# repo's CLI examples). Anything else is rejected by the runner's validation.
|
| 34 |
RESOLUTIONS = [
|
|
|
|
|
|
|
|
|
|
| 35 |
("2048 × 3840 (4K, README turbo example)", 2048, 3840),
|
| 36 |
("2176 × 3840 (4K, README incremental example)", 2176, 3840),
|
| 37 |
-
("1280 × 1920", 1280, 1920),
|
| 38 |
-
("704 × 1280", 704, 1280),
|
| 39 |
-
("640 × 1152", 640, 1152),
|
| 40 |
-
("384 × 640", 384, 640),
|
| 41 |
]
|
| 42 |
|
| 43 |
-
DEFAULT_HEIGHT, DEFAULT_WIDTH =
|
| 44 |
|
| 45 |
# Incremental input/decoding keeps RAM bounded at high resolutions: only one
|
| 46 |
# decode segment of frames is resident at a time (README's 4K path).
|
|
@@ -84,12 +82,13 @@ def _estimate_duration(video, resolution, temporal_compression, color_correction
|
|
| 84 |
_, height, width = RESOLUTIONS[resolution]
|
| 85 |
compression = int(temporal_compression)
|
| 86 |
pixels = height * width
|
| 87 |
-
# ~
|
| 88 |
-
#
|
| 89 |
-
|
|
|
|
| 90 |
frames = int(max_frames) if max_frames else 128
|
| 91 |
-
base *= max(frames / 128.0, 0.
|
| 92 |
-
return round(min(max(base * 1.15, 45),
|
| 93 |
|
| 94 |
|
| 95 |
@spaces.GPU(duration=_estimate_duration)
|
|
@@ -159,11 +158,11 @@ def upscale_video(
|
|
| 159 |
|
| 160 |
WARNING_MD = (
|
| 161 |
"**Heads-up:** higher resolutions and lower temporal compression cost "
|
| 162 |
-
"real GPU time. Start with the default (
|
| 163 |
"the examples; 4K targets can take minutes on ZeroGPU."
|
| 164 |
)
|
| 165 |
|
| 166 |
-
with gr.Blocks(
|
| 167 |
gr.Markdown(
|
| 168 |
"# ⚡ FlashVSR+ — Efficient Video Super-Resolution\n"
|
| 169 |
"One-step diffusion VSR with hybrid attention and a TinyDecoder. "
|
|
@@ -176,9 +175,9 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="FlashVSR+ Video Super-Resolution
|
|
| 176 |
resolution = gr.Dropdown(
|
| 177 |
choices=[r[0] for r in RESOLUTIONS],
|
| 178 |
type="index",
|
| 179 |
-
value=RESOLUTIONS[
|
| 180 |
label="Output resolution",
|
| 181 |
-
info="Target output size (both sides
|
| 182 |
)
|
| 183 |
with gr.Accordion("Advanced options", open=False):
|
| 184 |
temporal_compression = gr.Radio(
|
|
@@ -214,9 +213,9 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="FlashVSR+ Video Super-Resolution
|
|
| 214 |
|
| 215 |
gr.Examples(
|
| 216 |
examples=[
|
| 217 |
-
["examples/case_1.mp4", RESOLUTIONS[
|
| 218 |
-
["examples/case_0.mp4", RESOLUTIONS[
|
| 219 |
-
["examples/case_2.mp4", RESOLUTIONS[
|
| 220 |
],
|
| 221 |
inputs=[video_in, resolution, temporal_compression, color_correction, max_frames],
|
| 222 |
outputs=video_out,
|
|
@@ -227,4 +226,4 @@ with gr.Blocks(theme=gr.themes.Citrus(), title="FlashVSR+ Video Super-Resolution
|
|
| 227 |
label="Example inputs (from the FlashVSR+ repo)",
|
| 228 |
)
|
| 229 |
|
| 230 |
-
demo.launch(mcp_server=True)
|
|
|
|
| 29 |
from inference.pipeline import build_inference_pipeline # noqa: E402
|
| 30 |
from inference.request import InferenceRequest # noqa: E402
|
| 31 |
|
| 32 |
+
# Output resolutions (both sides divisible by 128 — a hard requirement).
|
|
|
|
| 33 |
RESOLUTIONS = [
|
| 34 |
+
("1024 × 1920 (README base example)", 1024, 1920),
|
| 35 |
+
("512 × 896", 512, 896),
|
| 36 |
+
("384 × 640", 384, 640),
|
| 37 |
("2048 × 3840 (4K, README turbo example)", 2048, 3840),
|
| 38 |
("2176 × 3840 (4K, README incremental example)", 2176, 3840),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
]
|
| 40 |
|
| 41 |
+
DEFAULT_HEIGHT, DEFAULT_WIDTH = 512, 896
|
| 42 |
|
| 43 |
# Incremental input/decoding keeps RAM bounded at high resolutions: only one
|
| 44 |
# decode segment of frames is resident at a time (README's 4K path).
|
|
|
|
| 82 |
_, height, width = RESOLUTIONS[resolution]
|
| 83 |
compression = int(temporal_compression)
|
| 84 |
pixels = height * width
|
| 85 |
+
# ~40 s for 512*896 pixels at compression 4 on a cold worker; runtime
|
| 86 |
+
# scales with pixels and inversely with compression (compression 1 has
|
| 87 |
+
# ~4x the chunk count of compression 4).
|
| 88 |
+
base = 40.0 * pixels / (512 * 896) * (4.0 / compression)
|
| 89 |
frames = int(max_frames) if max_frames else 128
|
| 90 |
+
base *= max(frames / 128.0, 0.3)
|
| 91 |
+
return round(min(max(base * 1.15, 45), 420))
|
| 92 |
|
| 93 |
|
| 94 |
@spaces.GPU(duration=_estimate_duration)
|
|
|
|
| 158 |
|
| 159 |
WARNING_MD = (
|
| 160 |
"**Heads-up:** higher resolutions and lower temporal compression cost "
|
| 161 |
+
"real GPU time. Start with the default (512 × 896, compression 4) or use "
|
| 162 |
"the examples; 4K targets can take minutes on ZeroGPU."
|
| 163 |
)
|
| 164 |
|
| 165 |
+
with gr.Blocks(title="FlashVSR+ Video Super-Resolution") as demo:
|
| 166 |
gr.Markdown(
|
| 167 |
"# ⚡ FlashVSR+ — Efficient Video Super-Resolution\n"
|
| 168 |
"One-step diffusion VSR with hybrid attention and a TinyDecoder. "
|
|
|
|
| 175 |
resolution = gr.Dropdown(
|
| 176 |
choices=[r[0] for r in RESOLUTIONS],
|
| 177 |
type="index",
|
| 178 |
+
value=RESOLUTIONS[1][0],
|
| 179 |
label="Output resolution",
|
| 180 |
+
info="Target output size (both sides must be multiples of 128); input is center-cropped and resized to it",
|
| 181 |
)
|
| 182 |
with gr.Accordion("Advanced options", open=False):
|
| 183 |
temporal_compression = gr.Radio(
|
|
|
|
| 213 |
|
| 214 |
gr.Examples(
|
| 215 |
examples=[
|
| 216 |
+
["examples/case_1.mp4", RESOLUTIONS[1][0], 4, False, 33],
|
| 217 |
+
["examples/case_0.mp4", RESOLUTIONS[1][0], 4, False, 97],
|
| 218 |
+
["examples/case_2.mp4", RESOLUTIONS[2][0], 4, False, 65],
|
| 219 |
],
|
| 220 |
inputs=[video_in, resolution, temporal_compression, color_correction, max_frames],
|
| 221 |
outputs=video_out,
|
|
|
|
| 226 |
label="Example inputs (from the FlashVSR+ repo)",
|
| 227 |
)
|
| 228 |
|
| 229 |
+
demo.launch(theme=gr.themes.Citrus(), mcp_server=True)
|