Yaron Koresh commited on
Commit
4afc319
·
verified ·
1 Parent(s): 6e8995d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -36
app.py CHANGED
@@ -16,7 +16,7 @@ import threading
16
  import asyncio
17
  from queue import Queue as BlockingQueue
18
  from functools import partial
19
- from multiprocessing import Process
20
 
21
  # external
22
 
@@ -137,10 +137,7 @@ def parallel(*pairs):
137
  return
138
  if len(pairs) == 1:
139
  pairs = pairs[0]
140
-
141
- out = []
142
  running_tasks = []
143
-
144
  for pair in pairs:
145
  task = pair.pop(0)
146
  running_tasks.append(Process(target=task, args=(pair,)))
@@ -148,8 +145,6 @@ def parallel(*pairs):
148
  running_task.start()
149
  for running_task in running_tasks:
150
  running_task.join()
151
- out.append(running_task.get())
152
- return out
153
 
154
  # functionality
155
 
@@ -202,33 +197,37 @@ def generate_random_string(length):
202
  characters = str(ascii_letters + digits)
203
  return ''.join(random.choice(characters) for _ in range(length))
204
 
205
- def calc(img,p1,p2,motion):
206
- global last_motion
207
- global pipe
208
-
209
- if last_motion != motion:
210
- if last_motion != "":
211
- pipe.unload_lora_weights()
212
- if motion != "":
213
- pipe.load_lora_weights(motion, adapter_name="motion")
214
- pipe.fuse_lora()
215
- pipe.set_adapters("motion", [0.7])
216
- last_motion = motion
217
-
218
- pipe.to(device,dtype=dtype)
219
-
220
- return pipe(
221
- prompt=p1,
222
- negative_prompt=p2,
223
- height=height,
224
- width=width,
225
- ip_adapter_image=img.convert("RGB"),
226
- num_inference_steps=step,
227
- guidance_scale=accu,
228
- num_frames=(fps*time)
229
- )
230
-
231
- def handle(*inp):
 
 
 
 
232
 
233
  inp = list(inp)
234
 
@@ -251,9 +250,9 @@ def handle(*inp):
251
  ln = len(result)
252
 
253
  parargs = [[calc,*inp] for i in range(ln)]
254
- out_pipe = parallel(parargs)
255
  names = []
256
- for i in out_pipe:
257
  name = generate_random_string(12)+".png"
258
  export_to_gif(i.frames[0],name,fps=fps)
259
  names.append( name )
@@ -314,7 +313,7 @@ def ui():
314
  prompt.submit,
315
  prompt2.submit
316
  ],
317
- fn=handle,
318
  inputs=[img,prompt,prompt2,motion],
319
  outputs=result
320
  )
 
16
  import asyncio
17
  from queue import Queue as BlockingQueue
18
  from functools import partial
19
+ from multiprocessing import Process, , Queue
20
 
21
  # external
22
 
 
137
  return
138
  if len(pairs) == 1:
139
  pairs = pairs[0]
 
 
140
  running_tasks = []
 
141
  for pair in pairs:
142
  task = pair.pop(0)
143
  running_tasks.append(Process(target=task, args=(pair,)))
 
145
  running_task.start()
146
  for running_task in running_tasks:
147
  running_task.join()
 
 
148
 
149
  # functionality
150
 
 
197
  characters = str(ascii_letters + digits)
198
  return ''.join(random.choice(characters) for _ in range(length))
199
 
200
+ def handle_generate(*inp):
201
+
202
+ calc_out = []
203
+
204
+ def calc(img,p1,p2,motion):
205
+ global last_motion
206
+ global pipe
207
+
208
+ if last_motion != motion:
209
+ if last_motion != "":
210
+ pipe.unload_lora_weights()
211
+ if motion != "":
212
+ pipe.load_lora_weights(motion, adapter_name="motion")
213
+ pipe.fuse_lora()
214
+ pipe.set_adapters("motion", [0.7])
215
+ last_motion = motion
216
+
217
+ pipe.to(device,dtype=dtype)
218
+
219
+ calc_out.append(
220
+ pipe(
221
+ prompt=p1,
222
+ negative_prompt=p2,
223
+ height=height,
224
+ width=width,
225
+ ip_adapter_image=img.convert("RGB"),
226
+ num_inference_steps=step,
227
+ guidance_scale=accu,
228
+ num_frames=(fps*time)
229
+ )
230
+ )
231
 
232
  inp = list(inp)
233
 
 
250
  ln = len(result)
251
 
252
  parargs = [[calc,*inp] for i in range(ln)]
253
+ parallel(parargs)
254
  names = []
255
+ for i in calc_out:
256
  name = generate_random_string(12)+".png"
257
  export_to_gif(i.frames[0],name,fps=fps)
258
  names.append( name )
 
313
  prompt.submit,
314
  prompt2.submit
315
  ],
316
+ fn=handle_generate,
317
  inputs=[img,prompt,prompt2,motion],
318
  outputs=result
319
  )