VicFonch commited on
app.py: New styles
Browse files
app.py
CHANGED
|
@@ -26,7 +26,10 @@ def to_numpy(img_tensor: torch.Tensor) -> np.ndarray:
|
|
| 26 |
img_np = np.clip(img_np, 0, 1)
|
| 27 |
return (img_np * 255).astype(np.uint8)
|
| 28 |
|
| 29 |
-
def interpolate(img0_pil
|
|
|
|
|
|
|
|
|
|
| 30 |
img0 = transform(img0_pil.convert("RGB")).unsqueeze(0).to(device)
|
| 31 |
img2 = transform(img2_pil.convert("RGB")).unsqueeze(0).to(device)
|
| 32 |
|
|
@@ -49,34 +52,60 @@ def interpolate(img0_pil, img2_pil, tau=0.5, num_samples=1):
|
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Error during interpolation: {e}")
|
| 51 |
return None, None
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
-
demo
|
|
|
|
|
|
|
|
|
| 26 |
img_np = np.clip(img_np, 0, 1)
|
| 27 |
return (img_np * 255).astype(np.uint8)
|
| 28 |
|
| 29 |
+
def interpolate(img0_pil: Image.Image,
|
| 30 |
+
img2_pil: Image.Image,
|
| 31 |
+
tau: float=0.5,
|
| 32 |
+
num_samples: int=1) -> tuple:
|
| 33 |
img0 = transform(img0_pil.convert("RGB")).unsqueeze(0).to(device)
|
| 34 |
img2 = transform(img2_pil.convert("RGB")).unsqueeze(0).to(device)
|
| 35 |
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
print(f"Error during interpolation: {e}")
|
| 54 |
return None, None
|
| 55 |
+
|
| 56 |
|
| 57 |
+
# Lo integras en Blocks y le agregas HTML arriba
|
| 58 |
+
def build_demo() -> gr.Blocks:
|
| 59 |
+
header = """
|
| 60 |
+
<div style="text-align: center; padding: 1rem 0;">
|
| 61 |
+
<h1 style="font-size: 2.2rem; margin-bottom: 0.4rem;">ποΈ Multi-Input ResShift Diffusion VFI</h1>
|
| 62 |
+
<p style="font-size: 1.1rem; color: #555; margin-bottom: 1rem;">
|
| 63 |
+
Efficient and stochastic video frame interpolation for hand-drawn animation
|
| 64 |
+
</p>
|
| 65 |
+
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 10px;">
|
| 66 |
+
<a href="https://arxiv.org/pdf/2504.05402">
|
| 67 |
+
<img src="https://img.shields.io/badge/arXiv-Paper-A42C25.svg" alt="arXiv">
|
| 68 |
+
</a>
|
| 69 |
+
<a href="https://huggingface.co/vfontech/Multiple-Input-Resshift-VFI">
|
| 70 |
+
<img src="https://img.shields.io/badge/π€-Model-ffbd45.svg" alt="HF">
|
| 71 |
+
</a>
|
| 72 |
+
<a href="https://colab.research.google.com/drive/1MGYycbNMW6Mxu5MUqw_RW_xxiVeHK5Aa#scrollTo=EKaYCioiP3tQ">
|
| 73 |
+
<img src="https://img.shields.io/badge/Colab-Demo-green.svg" alt="Colab">
|
| 74 |
+
</a>
|
| 75 |
+
<a href="https://github.com/VicFonch/Multi-Input-Resshift-Diffusion-VFI">
|
| 76 |
+
<img src="https://img.shields.io/badge/GitHub-Code-blue.svg?logo=github" alt="GitHub">
|
| 77 |
+
</a>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
"""
|
| 81 |
+
with gr.Blocks() as demo:
|
| 82 |
+
gr.HTML(header)
|
| 83 |
+
gr.Interface(
|
| 84 |
+
fn=interpolate,
|
| 85 |
+
inputs=[
|
| 86 |
+
gr.Image(type="pil", label="Initial Image (frame1)"),
|
| 87 |
+
gr.Image(type="pil", label="Final Image (frame3)"),
|
| 88 |
+
gr.Slider(0.0, 1.0, step=0.05, value=0.5, label="Tau Value (only if Num Samples = 1)"),
|
| 89 |
+
gr.Slider(1, 15, step=1, value=1, label="Number of Samples"),
|
| 90 |
+
],
|
| 91 |
+
outputs=[
|
| 92 |
+
gr.Image(label="Interpolated Image (if num_samples = 1)"),
|
| 93 |
+
gr.Video(label="Interpolation in video (if num_samples > 1)"),
|
| 94 |
+
],
|
| 95 |
+
#title="Multi-Input ResShift Diffusion VFI",
|
| 96 |
+
description=(
|
| 97 |
+
"Video interpolation using Conditional Residual Diffusion.\n"
|
| 98 |
+
"- All images are resized to 256x448.\n"
|
| 99 |
+
"- If `Number of Samples = 1`, generates only one intermediate image with the given Tau value.\n"
|
| 100 |
+
"- If `Number of Samples > 1`, ignores Tau and generates a sequence of interpolated images."
|
| 101 |
+
),
|
| 102 |
+
examples=[
|
| 103 |
+
["_data/example_images/frame1.png", "_data/example_images/frame3.png", 0.5, 1],
|
| 104 |
+
],
|
| 105 |
+
)
|
| 106 |
+
return demo
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
+
demo = build_demo()
|
| 110 |
+
#demo.launch(server_name="0.0.0.0", ssr_mode=False)
|
| 111 |
+
demo.launch()
|