Spaces:
Paused
Paused
Update app_gradio.py
Browse files- app_gradio.py +36 -27
app_gradio.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import cv2
|
| 3 |
import torch
|
|
@@ -22,13 +23,19 @@ from text2vid_modded import TextToVideoSDPipelineModded
|
|
| 22 |
from invert_utils import ddim_inversion as dd_inversion
|
| 23 |
from gifs_filter import filter
|
| 24 |
import subprocess
|
| 25 |
-
import spaces
|
| 26 |
|
|
|
|
| 27 |
|
| 28 |
def load_frames(image: Image, mode='RGBA'):
|
| 29 |
return np.array([np.array(frame.convert(mode)) for frame in ImageSequence.Iterator(image)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
def run_setup():
|
| 33 |
try:
|
| 34 |
# Step 1: Install Git LFS
|
|
@@ -53,7 +60,7 @@ def run_setup():
|
|
| 53 |
|
| 54 |
# Automatically run setup during app initialization
|
| 55 |
run_setup()
|
| 56 |
-
|
| 57 |
|
| 58 |
def save_gif(frames, path):
|
| 59 |
imageio.mimsave(
|
|
@@ -116,7 +123,7 @@ def initialize_pipeline(model: str, device: str = "cuda"):
|
|
| 116 |
return pipe, pipe.scheduler
|
| 117 |
|
| 118 |
# Initialize the models
|
| 119 |
-
LORA_CHECKPOINT = "checkpoint-2500"
|
| 120 |
os.environ["TORCH_CUDNN_V8_API_ENABLED"] = "1"
|
| 121 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 122 |
dtype = torch.bfloat16
|
|
@@ -223,7 +230,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 223 |
"""
|
| 224 |
)
|
| 225 |
|
| 226 |
-
with gr.Tab("
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
with gr.Column():
|
|
@@ -255,40 +262,42 @@ with gr.Blocks(css=css) as demo:
|
|
| 255 |
value=0.5,
|
| 256 |
step=0.1,
|
| 257 |
label="Motion Strength"
|
| 258 |
-
)
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
|
|
|
|
|
|
| 261 |
generate_btn = gr.Button(
|
| 262 |
"Generate Animation",
|
| 263 |
variant="primary",
|
| 264 |
elem_classes="generate-btn",
|
| 265 |
interactive=True,
|
| 266 |
)
|
| 267 |
-
|
| 268 |
-
with gr.Column():
|
| 269 |
-
gr.Examples(
|
| 270 |
-
examples=[
|
| 271 |
-
['./static/examples/sketch1.png', 'The camel walks slowly'],
|
| 272 |
-
['./static/examples/sketch2.png', 'The wine in the wine glass sways from side to side'],
|
| 273 |
-
['./static/examples/sketch3.png', 'The squirrel is eating a nut'],
|
| 274 |
-
['./static/examples/sketch4.png', 'The surfer surfs on the waves'],
|
| 275 |
-
['./static/examples/sketch5.png', 'A galloping horse'],
|
| 276 |
-
['./static/examples/sketch6.png', 'The cat walks forward'],
|
| 277 |
-
['./static/examples/sketch7.png', 'The eagle flies in the sky'],
|
| 278 |
-
['./static/examples/sketch8.png', 'The flower is blooming slowly'],
|
| 279 |
-
['./static/examples/sketch9.png', 'The reindeer looks around'],
|
| 280 |
-
['./static/examples/sketch10.png', 'The cloud floats in the sky'],
|
| 281 |
-
['./static/examples/sketch11.png', 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.'],
|
| 282 |
-
['./static/examples/sketch12.png', 'The biker rides on the road']
|
| 283 |
-
],
|
| 284 |
-
inputs=[input_sketch, motion_prompt],
|
| 285 |
-
examples_per_page=4,
|
| 286 |
-
)
|
| 287 |
|
| 288 |
-
with gr.Tab("Draw"):
|
| 289 |
with gr.Row():
|
| 290 |
with gr.Column():
|
| 291 |
draw_sketchpad = gr.Sketchpad(
|
|
|
|
| 292 |
value={
|
| 293 |
"background": "./static/examples/background.jpeg",
|
| 294 |
"layers": None,
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import os
|
| 3 |
import cv2
|
| 4 |
import torch
|
|
|
|
| 23 |
from invert_utils import ddim_inversion as dd_inversion
|
| 24 |
from gifs_filter import filter
|
| 25 |
import subprocess
|
|
|
|
| 26 |
|
| 27 |
+
from huggingface_hub import snapshot_download
|
| 28 |
|
| 29 |
def load_frames(image: Image, mode='RGBA'):
|
| 30 |
return np.array([np.array(frame.convert(mode)) for frame in ImageSequence.Iterator(image)])
|
| 31 |
+
|
| 32 |
+
os.makedirs("t2v_sketch-lora", exist_ok=True)
|
| 33 |
+
snapshot_download(
|
| 34 |
+
repo_id="Hmrishav/t2v_sketch-lora",
|
| 35 |
+
local_dir="./t2v_sketch-lora"
|
| 36 |
+
)
|
| 37 |
|
| 38 |
+
"""
|
| 39 |
def run_setup():
|
| 40 |
try:
|
| 41 |
# Step 1: Install Git LFS
|
|
|
|
| 60 |
|
| 61 |
# Automatically run setup during app initialization
|
| 62 |
run_setup()
|
| 63 |
+
"""
|
| 64 |
|
| 65 |
def save_gif(frames, path):
|
| 66 |
imageio.mimsave(
|
|
|
|
| 123 |
return pipe, pipe.scheduler
|
| 124 |
|
| 125 |
# Initialize the models
|
| 126 |
+
LORA_CHECKPOINT = "t2v_sketch-lora/checkpoint-2500"
|
| 127 |
os.environ["TORCH_CUDNN_V8_API_ENABLED"] = "1"
|
| 128 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 129 |
dtype = torch.bfloat16
|
|
|
|
| 230 |
"""
|
| 231 |
)
|
| 232 |
|
| 233 |
+
with gr.Tab("Upload your sketch"):
|
| 234 |
|
| 235 |
with gr.Row():
|
| 236 |
with gr.Column():
|
|
|
|
| 262 |
value=0.5,
|
| 263 |
step=0.1,
|
| 264 |
label="Motion Strength"
|
| 265 |
+
)
|
| 266 |
|
| 267 |
+
with gr.Column():
|
| 268 |
+
gr.Examples(
|
| 269 |
+
examples=[
|
| 270 |
+
['./static/examples/sketch1.png', 'The camel walks slowly'],
|
| 271 |
+
['./static/examples/sketch2.png', 'The wine in the wine glass sways from side to side'],
|
| 272 |
+
['./static/examples/sketch3.png', 'The squirrel is eating a nut'],
|
| 273 |
+
['./static/examples/sketch4.png', 'The surfer surfs on the waves'],
|
| 274 |
+
['./static/examples/sketch5.png', 'A galloping horse'],
|
| 275 |
+
['./static/examples/sketch6.png', 'The cat walks forward'],
|
| 276 |
+
['./static/examples/sketch7.png', 'The eagle flies in the sky'],
|
| 277 |
+
['./static/examples/sketch8.png', 'The flower is blooming slowly'],
|
| 278 |
+
['./static/examples/sketch9.png', 'The reindeer looks around'],
|
| 279 |
+
['./static/examples/sketch10.png', 'The cloud floats in the sky'],
|
| 280 |
+
['./static/examples/sketch11.png', 'The jazz saxophonist performs on stage with a rhythmic sway, his upper body sways subtly to the rhythm of the music.'],
|
| 281 |
+
['./static/examples/sketch12.png', 'The biker rides on the road']
|
| 282 |
+
],
|
| 283 |
+
inputs=[input_sketch, motion_prompt],
|
| 284 |
+
examples_per_page=4,
|
| 285 |
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
generate_btn = gr.Button(
|
| 289 |
"Generate Animation",
|
| 290 |
variant="primary",
|
| 291 |
elem_classes="generate-btn",
|
| 292 |
interactive=True,
|
| 293 |
)
|
| 294 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
+
with gr.Tab("Draw your own"):
|
| 297 |
with gr.Row():
|
| 298 |
with gr.Column():
|
| 299 |
draw_sketchpad = gr.Sketchpad(
|
| 300 |
+
label="Draw your own Sketch",
|
| 301 |
value={
|
| 302 |
"background": "./static/examples/background.jpeg",
|
| 303 |
"layers": None,
|