Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -25,13 +25,9 @@ from diffusers.models.modeling_utils import ModelMixin
|
|
25 |
from huggingface_hub import hf_hub_download
|
26 |
from safetensors.torch import load_file, save_file
|
27 |
from diffusers import DiffusionPipeline, AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler, DDIMScheduler, StableDiffusionXLPipeline, UNet2DConditionModel, AutoencoderKL, UNet3DConditionModel
|
28 |
-
|
29 |
-
|
30 |
-
from
|
31 |
-
from numba.cuda import jit as gpu, grid, as_cuda_array as tensor2array
|
32 |
-
from numba.types import unicode_type as string
|
33 |
-
from PIL.Image import fromarray as array2image
|
34 |
-
import numpy as np
|
35 |
|
36 |
# logging
|
37 |
|
@@ -49,10 +45,14 @@ formatter = logging.Formatter('\n >>> [%(levelname)s] %(asctime)s %(name)s: %(me
|
|
49 |
handler2.setFormatter(formatter)
|
50 |
root.addHandler(handler2)
|
51 |
|
52 |
-
#
|
53 |
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# constant data
|
58 |
|
@@ -69,8 +69,8 @@ adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-
|
|
69 |
# precision data
|
70 |
|
71 |
fast=True
|
72 |
-
fps=
|
73 |
-
time=
|
74 |
width=384
|
75 |
height=768
|
76 |
step=40
|
@@ -135,7 +135,6 @@ pipe.load_ip_adapter("h94/IP-Adapter", subfolder="models", weight_name="ip-adapt
|
|
135 |
pipe.enable_vae_slicing()
|
136 |
pipe.enable_free_init(method="butterworth", use_fast_sampling=fast)
|
137 |
|
138 |
-
|
139 |
# functionality
|
140 |
|
141 |
def run(cmd):
|
@@ -187,26 +186,22 @@ def generate_random_string(length):
|
|
187 |
characters = str(ascii_letters + digits)
|
188 |
return ''.join(random.choice(characters) for _ in range(length))
|
189 |
|
190 |
-
@gpu(void( rgb[:], string[:], string[:], string[:] ))
|
191 |
def calc(img,p1,p2,motion):
|
192 |
-
global out_pipe
|
193 |
global last_motion
|
194 |
global pipe
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
if last_motion[0] != motion:
|
199 |
pipe.unload_lora_weights()
|
200 |
if inp[3] != "":
|
201 |
pipe.load_lora_weights(motion, adapter_name="motion")
|
202 |
pipe.fuse_lora()
|
203 |
pipe.set_adapters("motion", [0.7])
|
204 |
-
last_motion
|
205 |
|
206 |
pipe.to(device,dtype)
|
207 |
|
208 |
if p2=="":
|
209 |
-
|
210 |
prompt=p1,
|
211 |
height=height,
|
212 |
width=width,
|
@@ -216,7 +211,7 @@ def calc(img,p1,p2,motion):
|
|
216 |
num_frames=(fps*time)
|
217 |
)
|
218 |
|
219 |
-
|
220 |
prompt=p1,
|
221 |
negative_prompt=p2,
|
222 |
height=height,
|
@@ -227,6 +222,7 @@ def calc(img,p1,p2,motion):
|
|
227 |
num_frames=(fps*time)
|
228 |
)
|
229 |
|
|
|
230 |
def handle(*inp):
|
231 |
|
232 |
inp[1] = translate(inp[1],"english")
|
@@ -249,9 +245,10 @@ def handle(*inp):
|
|
249 |
inp[1] = array(inp[1])
|
250 |
inp[2] = array(inp[2])
|
251 |
inp[3] = array(inp[3])
|
252 |
-
|
253 |
-
|
254 |
for i in range(ln):
|
|
|
255 |
name = generate_random_string(12)+".png"
|
256 |
export_to_gif(out_pipe[i].frames[0],name,fps=fps)
|
257 |
out_pipe[i] = name
|
@@ -329,7 +326,7 @@ def entry():
|
|
329 |
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
330 |
|
331 |
ui()
|
332 |
-
events
|
333 |
|
334 |
# entry
|
335 |
|
|
|
25 |
from huggingface_hub import hf_hub_download
|
26 |
from safetensors.torch import load_file, save_file
|
27 |
from diffusers import DiffusionPipeline, AnimateDiffPipeline, MotionAdapter, EulerDiscreteScheduler, DDIMScheduler, StableDiffusionXLPipeline, UNet2DConditionModel, AutoencoderKL, UNet3DConditionModel
|
28 |
+
from numba import jit, void as vid, int64 as int, float64 as flt, boolean as bol, uint8 as rgb
|
29 |
+
from numba.types import unicode_type as str
|
30 |
+
from functools import partial
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# logging
|
33 |
|
|
|
45 |
handler2.setFormatter(formatter)
|
46 |
root.addHandler(handler2)
|
47 |
|
48 |
+
# jit decorator shortcuts
|
49 |
|
50 |
+
math = partial(jit, cache=True, parallel=True)
|
51 |
+
loop = partial(jit, cache=True, forceobj=True)
|
52 |
+
|
53 |
+
# storage data
|
54 |
+
|
55 |
+
last_motion=""
|
56 |
|
57 |
# constant data
|
58 |
|
|
|
69 |
# precision data
|
70 |
|
71 |
fast=True
|
72 |
+
fps=15
|
73 |
+
time=3
|
74 |
width=384
|
75 |
height=768
|
76 |
step=40
|
|
|
135 |
pipe.enable_vae_slicing()
|
136 |
pipe.enable_free_init(method="butterworth", use_fast_sampling=fast)
|
137 |
|
|
|
138 |
# functionality
|
139 |
|
140 |
def run(cmd):
|
|
|
186 |
characters = str(ascii_letters + digits)
|
187 |
return ''.join(random.choice(characters) for _ in range(length))
|
188 |
|
|
|
189 |
def calc(img,p1,p2,motion):
|
|
|
190 |
global last_motion
|
191 |
global pipe
|
192 |
|
193 |
+
if last_motion != motion:
|
|
|
|
|
194 |
pipe.unload_lora_weights()
|
195 |
if inp[3] != "":
|
196 |
pipe.load_lora_weights(motion, adapter_name="motion")
|
197 |
pipe.fuse_lora()
|
198 |
pipe.set_adapters("motion", [0.7])
|
199 |
+
last_motion = motion
|
200 |
|
201 |
pipe.to(device,dtype)
|
202 |
|
203 |
if p2=="":
|
204 |
+
return pipe(
|
205 |
prompt=p1,
|
206 |
height=height,
|
207 |
width=width,
|
|
|
211 |
num_frames=(fps*time)
|
212 |
)
|
213 |
|
214 |
+
return pipe(
|
215 |
prompt=p1,
|
216 |
negative_prompt=p2,
|
217 |
height=height,
|
|
|
222 |
num_frames=(fps*time)
|
223 |
)
|
224 |
|
225 |
+
@loop
|
226 |
def handle(*inp):
|
227 |
|
228 |
inp[1] = translate(inp[1],"english")
|
|
|
245 |
inp[1] = array(inp[1])
|
246 |
inp[2] = array(inp[2])
|
247 |
inp[3] = array(inp[3])
|
248 |
+
|
249 |
+
out_pipe = []
|
250 |
for i in range(ln):
|
251 |
+
out_pipe = calc(*inp)
|
252 |
name = generate_random_string(12)+".png"
|
253 |
export_to_gif(out_pipe[i].frames[0],name,fps=fps)
|
254 |
out_pipe[i] = name
|
|
|
326 |
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
327 |
|
328 |
ui()
|
329 |
+
events()
|
330 |
|
331 |
# entry
|
332 |
|