Spaces:
Running on Zero
Running on Zero
Use ImageSlider comparison output
Browse files- README.md +2 -1
- app.py +10 -26
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -32,7 +32,8 @@ which is gated and requires an `HF_TOKEN` Space secret with model access.
|
|
| 32 |
|
| 33 |
Upload a low-resolution square image, typically around 128 x 128, or choose one
|
| 34 |
of the bundled examples. Click **Super-Resolve** to run the 28-step ASASR sampler
|
| 35 |
-
and return
|
|
|
|
| 36 |
|
| 37 |
## License
|
| 38 |
|
|
|
|
| 32 |
|
| 33 |
Upload a low-resolution square image, typically around 128 x 128, or choose one
|
| 34 |
of the bundled examples. Click **Super-Resolve** to run the 28-step ASASR sampler
|
| 35 |
+
and return an interactive slider comparing the bicubic low-resolution input
|
| 36 |
+
against the 512 x 512 ASASR result.
|
| 37 |
|
| 38 |
## License
|
| 39 |
|
app.py
CHANGED
|
@@ -14,8 +14,9 @@ from pathlib import Path
|
|
| 14 |
from typing import Optional, Tuple
|
| 15 |
|
| 16 |
import gradio as gr
|
|
|
|
| 17 |
from huggingface_hub import snapshot_download
|
| 18 |
-
from PIL import Image,
|
| 19 |
|
| 20 |
import torch
|
| 21 |
from diffusers.pipelines import FluxPipeline
|
|
@@ -161,20 +162,6 @@ def _prepare_input(image: Image.Image) -> Image.Image:
|
|
| 161 |
return image.resize((TARGET_RESOLUTION, TARGET_RESOLUTION), Image.Resampling.BICUBIC)
|
| 162 |
|
| 163 |
|
| 164 |
-
def _comparison_image(lr_image: Image.Image, sr_image: Image.Image) -> Image.Image:
|
| 165 |
-
label_h = 34
|
| 166 |
-
width = TARGET_RESOLUTION * 2
|
| 167 |
-
height = TARGET_RESOLUTION + label_h
|
| 168 |
-
canvas = Image.new("RGB", (width, height), "#111827")
|
| 169 |
-
draw = ImageDraw.Draw(canvas)
|
| 170 |
-
draw.text((18, 10), "Input LR, bicubic to 512", fill="#f9fafb")
|
| 171 |
-
draw.text((TARGET_RESOLUTION + 18, 10), "ASASR output, 512 x 512", fill="#f9fafb")
|
| 172 |
-
canvas.paste(lr_image, (0, label_h))
|
| 173 |
-
canvas.paste(sr_image, (TARGET_RESOLUTION, label_h))
|
| 174 |
-
draw.line((TARGET_RESOLUTION, 0, TARGET_RESOLUTION, height), fill="#111827", width=3)
|
| 175 |
-
return canvas
|
| 176 |
-
|
| 177 |
-
|
| 178 |
def _gpu_duration(*args, **kwargs) -> int:
|
| 179 |
value = os.environ.get("ASASR_GPU_DURATION", "45")
|
| 180 |
try:
|
|
@@ -216,7 +203,6 @@ def super_resolve(
|
|
| 216 |
).images[0]
|
| 217 |
result = adain_color_fix(result, lr_image).convert("RGB")
|
| 218 |
LAST_INFERENCE_SECONDS = time.perf_counter() - start
|
| 219 |
-
comparison = _comparison_image(lr_image, result)
|
| 220 |
load_text = (
|
| 221 |
f"Model load: {PIPELINE_LOAD_SECONDS:.1f}s. "
|
| 222 |
if PIPELINE_LOAD_SECONDS is not None
|
|
@@ -227,7 +213,7 @@ def super_resolve(
|
|
| 227 |
f"{load_text}Inference: {LAST_INFERENCE_SECONDS:.1f}s."
|
| 228 |
)
|
| 229 |
print(f"[ASASR] {status}")
|
| 230 |
-
return
|
| 231 |
|
| 232 |
|
| 233 |
_startup_prefetch()
|
|
@@ -288,15 +274,13 @@ with gr.Blocks(title="ASASR Super-Resolution") as demo:
|
|
| 288 |
)
|
| 289 |
run_button = gr.Button("Super-Resolve", variant="primary")
|
| 290 |
with gr.Column(scale=2, min_width=420):
|
| 291 |
-
|
| 292 |
label="Input LR | ASASR HR",
|
| 293 |
type="pil",
|
| 294 |
-
height=
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
type="pil",
|
| 299 |
-
height=420,
|
| 300 |
)
|
| 301 |
status = gr.Textbox(
|
| 302 |
label="Runtime",
|
|
@@ -308,7 +292,7 @@ with gr.Blocks(title="ASASR Super-Resolution") as demo:
|
|
| 308 |
gr.Examples(
|
| 309 |
examples=EXAMPLE_FILES,
|
| 310 |
inputs=input_image,
|
| 311 |
-
outputs=[
|
| 312 |
fn=super_resolve,
|
| 313 |
cache_examples=True,
|
| 314 |
cache_mode="lazy",
|
|
@@ -318,7 +302,7 @@ with gr.Blocks(title="ASASR Super-Resolution") as demo:
|
|
| 318 |
run_button.click(
|
| 319 |
fn=super_resolve,
|
| 320 |
inputs=input_image,
|
| 321 |
-
outputs=[
|
| 322 |
api_name="super_resolve",
|
| 323 |
)
|
| 324 |
|
|
|
|
| 14 |
from typing import Optional, Tuple
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
+
from gradio_imageslider import ImageSlider
|
| 18 |
from huggingface_hub import snapshot_download
|
| 19 |
+
from PIL import Image, ImageOps
|
| 20 |
|
| 21 |
import torch
|
| 22 |
from diffusers.pipelines import FluxPipeline
|
|
|
|
| 162 |
return image.resize((TARGET_RESOLUTION, TARGET_RESOLUTION), Image.Resampling.BICUBIC)
|
| 163 |
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
def _gpu_duration(*args, **kwargs) -> int:
|
| 166 |
value = os.environ.get("ASASR_GPU_DURATION", "45")
|
| 167 |
try:
|
|
|
|
| 203 |
).images[0]
|
| 204 |
result = adain_color_fix(result, lr_image).convert("RGB")
|
| 205 |
LAST_INFERENCE_SECONDS = time.perf_counter() - start
|
|
|
|
| 206 |
load_text = (
|
| 207 |
f"Model load: {PIPELINE_LOAD_SECONDS:.1f}s. "
|
| 208 |
if PIPELINE_LOAD_SECONDS is not None
|
|
|
|
| 213 |
f"{load_text}Inference: {LAST_INFERENCE_SECONDS:.1f}s."
|
| 214 |
)
|
| 215 |
print(f"[ASASR] {status}")
|
| 216 |
+
return (lr_image, result), status
|
| 217 |
|
| 218 |
|
| 219 |
_startup_prefetch()
|
|
|
|
| 274 |
)
|
| 275 |
run_button = gr.Button("Super-Resolve", variant="primary")
|
| 276 |
with gr.Column(scale=2, min_width=420):
|
| 277 |
+
comparison_slider = ImageSlider(
|
| 278 |
label="Input LR | ASASR HR",
|
| 279 |
type="pil",
|
| 280 |
+
height=560,
|
| 281 |
+
position=0.5,
|
| 282 |
+
interactive=False,
|
| 283 |
+
slider_color="#2563eb",
|
|
|
|
|
|
|
| 284 |
)
|
| 285 |
status = gr.Textbox(
|
| 286 |
label="Runtime",
|
|
|
|
| 292 |
gr.Examples(
|
| 293 |
examples=EXAMPLE_FILES,
|
| 294 |
inputs=input_image,
|
| 295 |
+
outputs=[comparison_slider, status],
|
| 296 |
fn=super_resolve,
|
| 297 |
cache_examples=True,
|
| 298 |
cache_mode="lazy",
|
|
|
|
| 302 |
run_button.click(
|
| 303 |
fn=super_resolve,
|
| 304 |
inputs=input_image,
|
| 305 |
+
outputs=[comparison_slider, status],
|
| 306 |
api_name="super_resolve",
|
| 307 |
)
|
| 308 |
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio==6.10.0
|
|
|
|
| 2 |
spaces==0.50.4
|
| 3 |
diffusers==0.30.3
|
| 4 |
transformers==4.57.6
|
|
|
|
| 1 |
gradio==6.10.0
|
| 2 |
+
gradio_imageslider==0.0.20
|
| 3 |
spaces==0.50.4
|
| 4 |
diffusers==0.30.3
|
| 5 |
transformers==4.57.6
|