Commit
•
1298d15
1
Parent(s):
f5a44da
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from glob import glob
|
|
7 |
from pathlib import Path
|
8 |
from typing import Optional
|
9 |
|
|
|
10 |
import tempfile
|
11 |
import numpy as np
|
12 |
import cv2
|
@@ -188,6 +189,7 @@ model_select("AnimateLCM-SVD-xt-1.1.safetensors")
|
|
188 |
max_64_bit_int = 2**63 - 1
|
189 |
|
190 |
def sample(
|
|
|
191 |
image: Image,
|
192 |
seed: Optional[int] = 42,
|
193 |
randomize_seed: bool = False,
|
@@ -195,12 +197,16 @@ def sample(
|
|
195 |
fps_id: int = 8,
|
196 |
max_guidance_scale: float = 1.2,
|
197 |
min_guidance_scale: float = 1,
|
198 |
-
width: int =
|
199 |
-
height: int =
|
200 |
num_inference_steps: int = 4,
|
201 |
decoding_t: int = 4, # Number of frames decoded at a time! This eats most VRAM. Reduce if necessary.
|
202 |
output_folder: str = "outputs_gradio",
|
203 |
):
|
|
|
|
|
|
|
|
|
204 |
if image.mode == "RGBA":
|
205 |
image = image.convert("RGB")
|
206 |
|
@@ -227,15 +233,19 @@ def sample(
|
|
227 |
export_to_video(frames, video_path, fps=fps_id)
|
228 |
torch.manual_seed(seed)
|
229 |
|
230 |
-
|
|
|
|
|
|
|
|
|
231 |
|
232 |
|
233 |
with gr.Blocks() as demo:
|
234 |
with gr.Row():
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
|
240 |
seed = gr.Slider(
|
241 |
label="Seed",
|
@@ -266,7 +276,7 @@ with gr.Blocks() as demo:
|
|
266 |
width = gr.Slider(
|
267 |
label="Width of input image",
|
268 |
info="It should be divisible by 64",
|
269 |
-
value=576, # 256, 320, 384, 448
|
270 |
minimum=256,
|
271 |
maximum=2048,
|
272 |
step=64,
|
@@ -274,7 +284,7 @@ with gr.Blocks() as demo:
|
|
274 |
height = gr.Slider(
|
275 |
label="Height of input image",
|
276 |
info="It should be divisible by 64",
|
277 |
-
value=320, # 256, 320, 384, 448
|
278 |
minimum=256,
|
279 |
maximum=1152,
|
280 |
)
|
@@ -304,7 +314,8 @@ with gr.Blocks() as demo:
|
|
304 |
generate_btn.click(
|
305 |
fn=sample,
|
306 |
inputs=[
|
307 |
-
|
|
|
308 |
seed,
|
309 |
randomize_seed,
|
310 |
motion_bucket_id,
|
@@ -315,8 +326,7 @@ with gr.Blocks() as demo:
|
|
315 |
height,
|
316 |
num_inference_steps,
|
317 |
],
|
318 |
-
outputs=
|
319 |
-
api_name="video",
|
320 |
)
|
321 |
|
322 |
if __name__ == "__main__":
|
|
|
7 |
from pathlib import Path
|
8 |
from typing import Optional
|
9 |
|
10 |
+
import base64
|
11 |
import tempfile
|
12 |
import numpy as np
|
13 |
import cv2
|
|
|
189 |
max_64_bit_int = 2**63 - 1
|
190 |
|
191 |
def sample(
|
192 |
+
secret_token: str,
|
193 |
image: Image,
|
194 |
seed: Optional[int] = 42,
|
195 |
randomize_seed: bool = False,
|
|
|
197 |
fps_id: int = 8,
|
198 |
max_guidance_scale: float = 1.2,
|
199 |
min_guidance_scale: float = 1,
|
200 |
+
width: int = 768,
|
201 |
+
height: int = 384,
|
202 |
num_inference_steps: int = 4,
|
203 |
decoding_t: int = 4, # Number of frames decoded at a time! This eats most VRAM. Reduce if necessary.
|
204 |
output_folder: str = "outputs_gradio",
|
205 |
):
|
206 |
+
if secret_token != SECRET_TOKEN:
|
207 |
+
raise gr.Error(
|
208 |
+
f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
|
209 |
+
|
210 |
if image.mode == "RGBA":
|
211 |
image = image.convert("RGB")
|
212 |
|
|
|
233 |
export_to_video(frames, video_path, fps=fps_id)
|
234 |
torch.manual_seed(seed)
|
235 |
|
236 |
+
# Read the content of the video file and encode it to base64
|
237 |
+
with open(video_path, "rb") as video_file:
|
238 |
+
video_base64 = base64.b64encode(video_file.read()).decode('utf-8')
|
239 |
+
|
240 |
+
return video_base64
|
241 |
|
242 |
|
243 |
with gr.Blocks() as demo:
|
244 |
with gr.Row():
|
245 |
+
|
246 |
+
image_input_base64 = gr.Textbox()
|
247 |
+
generate_btn = gr.Button("Generate")
|
248 |
+
video_output_base64 = gr.Textbox()
|
249 |
|
250 |
seed = gr.Slider(
|
251 |
label="Seed",
|
|
|
276 |
width = gr.Slider(
|
277 |
label="Width of input image",
|
278 |
info="It should be divisible by 64",
|
279 |
+
value=768, # 576, # 256, 320, 384, 448
|
280 |
minimum=256,
|
281 |
maximum=2048,
|
282 |
step=64,
|
|
|
284 |
height = gr.Slider(
|
285 |
label="Height of input image",
|
286 |
info="It should be divisible by 64",
|
287 |
+
value=384, # 320, # 256, 320, 384, 448
|
288 |
minimum=256,
|
289 |
maximum=1152,
|
290 |
)
|
|
|
314 |
generate_btn.click(
|
315 |
fn=sample,
|
316 |
inputs=[
|
317 |
+
secret_token,
|
318 |
+
image_input_base64,
|
319 |
seed,
|
320 |
randomize_seed,
|
321 |
motion_bucket_id,
|
|
|
326 |
height,
|
327 |
num_inference_steps,
|
328 |
],
|
329 |
+
outputs=video_output_base64,
|
|
|
330 |
)
|
331 |
|
332 |
if __name__ == "__main__":
|