Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -131,23 +131,20 @@ function custom(){
|
|
131 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
132 |
# @cpu1(cache=True)
|
133 |
# @cpu2(cache=True)
|
134 |
-
def run(
|
135 |
tx = cuda.threadIdx.x
|
136 |
bx = cuda.blockIdx.x
|
137 |
dx = cuda.blockDim.x
|
138 |
pos = tx + bx * dx
|
139 |
|
140 |
-
|
141 |
-
print(f"--> {cmd}")
|
142 |
-
result = 1
|
143 |
-
else:
|
144 |
-
result = subprocess.run(cmd, shell=True, capture_output=capture_output, env=env)
|
145 |
-
if assert_success and result.returncode != 0:
|
146 |
-
logging.error(
|
147 |
-
f"Command '{cmd}' failed with exit status code '{result.returncode}'. Exiting..."
|
148 |
-
)
|
149 |
-
sys.exit()
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
return result
|
152 |
|
153 |
@gpu(cache=True)
|
@@ -155,12 +152,14 @@ def run(cmd, assert_success=False, capture_output=False, env=None, dry_run=False
|
|
155 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
156 |
# @cpu1(cache=True)
|
157 |
# @cpu2(cache=True)
|
158 |
-
def translate(
|
159 |
tx = cuda.threadIdx.x
|
160 |
bx = cuda.blockIdx.x
|
161 |
dx = cuda.blockDim.x
|
162 |
pos = tx + bx * dx
|
163 |
|
|
|
|
|
164 |
if text == None or lang == None:
|
165 |
return ""
|
166 |
text = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', text)).lower().strip()
|
@@ -206,12 +205,14 @@ def translate(text,lang):
|
|
206 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
207 |
# @cpu1(cache=True)
|
208 |
# @cpu2(cache=True)
|
209 |
-
def generate_random_string(
|
210 |
tx = cuda.threadIdx.x
|
211 |
bx = cuda.blockIdx.x
|
212 |
dx = cuda.blockDim.x
|
213 |
pos = tx + bx * dx
|
214 |
|
|
|
|
|
215 |
characters = string.ascii_letters + string.digits
|
216 |
return ''.join(random.choice(characters) for _ in range(length))
|
217 |
|
@@ -221,12 +222,14 @@ def generate_random_string(length):
|
|
221 |
# @cpu1(cache=True)
|
222 |
# @cpu2(cache=True)
|
223 |
@spaces.GPU(duration=65)
|
224 |
-
def Piper(
|
225 |
tx = cuda.threadIdx.x
|
226 |
bx = cuda.blockIdx.x
|
227 |
dx = cuda.blockDim.x
|
228 |
pos = tx + bx * dx
|
229 |
|
|
|
|
|
230 |
global last_motion
|
231 |
global ip_loaded
|
232 |
|
@@ -267,16 +270,18 @@ def Piper(image,positive,negative,motion):
|
|
267 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
268 |
# @cpu1(cache=True)
|
269 |
# @cpu2(cache=True)
|
270 |
-
def infer(
|
271 |
tx = cuda.threadIdx.x
|
272 |
bx = cuda.blockIdx.x
|
273 |
dx = cuda.blockDim.x
|
274 |
pos = tx + bx * dx
|
275 |
|
|
|
|
|
276 |
print("infer: started")
|
277 |
|
278 |
p1 = pm["p"]
|
279 |
-
name = generate_random_string(12)+".png"
|
280 |
|
281 |
neg = pm["n"]
|
282 |
if neg != "":
|
@@ -289,7 +294,7 @@ def infer(pm):
|
|
289 |
|
290 |
if pm["i"] == None:
|
291 |
return None
|
292 |
-
out = Piper(pm["i"],posi,neg,pm["m"])
|
293 |
export_to_gif(out.frames[0],name,fps=fps)
|
294 |
return name
|
295 |
|
@@ -298,23 +303,23 @@ def infer(pm):
|
|
298 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
299 |
# @cpu1(cache=True)
|
300 |
# @cpu2(cache=True)
|
301 |
-
def handle(
|
302 |
tx = cuda.threadIdx.x
|
303 |
bx = cuda.blockIdx.x
|
304 |
dx = cuda.blockDim.x
|
305 |
pos = tx + bx * dx
|
306 |
|
307 |
-
|
308 |
-
|
|
|
|
|
309 |
pm = {"p":p1_en,"n":p2_en,"m":m,"i":i}
|
310 |
ln = len(result)
|
311 |
rng = list(range(ln))
|
312 |
arr = [pm for _ in rng]
|
313 |
#with Pool(f'{ ln }:ppn=2', queue='productionQ', timelimit='5:00:00', workdir='.') as pool:
|
314 |
#return pool.map(infer,arr)
|
315 |
-
ret = []
|
316 |
-
for _ in range(ln):
|
317 |
-
ret.append(infer,pm)
|
318 |
return ret
|
319 |
|
320 |
@gpu(cache=True)
|
@@ -376,7 +381,7 @@ def ui():
|
|
376 |
|
377 |
gr.on(
|
378 |
triggers=[run_button.click, prompt.submit, prompt2.submit],
|
379 |
-
fn=handle,inputs=[img,motion,prompt,prompt2,*result],outputs=result
|
380 |
)
|
381 |
demo.queue().launch()
|
382 |
|
|
|
131 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
132 |
# @cpu1(cache=True)
|
133 |
# @cpu2(cache=True)
|
134 |
+
def run(*args):
|
135 |
tx = cuda.threadIdx.x
|
136 |
bx = cuda.blockIdx.x
|
137 |
dx = cuda.blockDim.x
|
138 |
pos = tx + bx * dx
|
139 |
|
140 |
+
cmd=*args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
+
result = subprocess.run(cmd, shell=True, capture_output=True, env=None)
|
143 |
+
if result.returncode != 0:
|
144 |
+
logging.error(
|
145 |
+
f"Command '{cmd}' failed with exit status code '{result.returncode}'. Exiting..."
|
146 |
+
)
|
147 |
+
sys.exit()
|
148 |
return result
|
149 |
|
150 |
@gpu(cache=True)
|
|
|
152 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
153 |
# @cpu1(cache=True)
|
154 |
# @cpu2(cache=True)
|
155 |
+
def translate(*args):
|
156 |
tx = cuda.threadIdx.x
|
157 |
bx = cuda.blockIdx.x
|
158 |
dx = cuda.blockDim.x
|
159 |
pos = tx + bx * dx
|
160 |
|
161 |
+
text,lang=*args
|
162 |
+
|
163 |
if text == None or lang == None:
|
164 |
return ""
|
165 |
text = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', text)).lower().strip()
|
|
|
205 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
206 |
# @cpu1(cache=True)
|
207 |
# @cpu2(cache=True)
|
208 |
+
def generate_random_string(*args):
|
209 |
tx = cuda.threadIdx.x
|
210 |
bx = cuda.blockIdx.x
|
211 |
dx = cuda.blockDim.x
|
212 |
pos = tx + bx * dx
|
213 |
|
214 |
+
length=*args
|
215 |
+
|
216 |
characters = string.ascii_letters + string.digits
|
217 |
return ''.join(random.choice(characters) for _ in range(length))
|
218 |
|
|
|
222 |
# @cpu1(cache=True)
|
223 |
# @cpu2(cache=True)
|
224 |
@spaces.GPU(duration=65)
|
225 |
+
def Piper(*args):
|
226 |
tx = cuda.threadIdx.x
|
227 |
bx = cuda.blockIdx.x
|
228 |
dx = cuda.blockDim.x
|
229 |
pos = tx + bx * dx
|
230 |
|
231 |
+
image,positive,negative,motion=*args
|
232 |
+
|
233 |
global last_motion
|
234 |
global ip_loaded
|
235 |
|
|
|
270 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
271 |
# @cpu1(cache=True)
|
272 |
# @cpu2(cache=True)
|
273 |
+
def infer(args):
|
274 |
tx = cuda.threadIdx.x
|
275 |
bx = cuda.blockIdx.x
|
276 |
dx = cuda.blockDim.x
|
277 |
pos = tx + bx * dx
|
278 |
|
279 |
+
pm = *args
|
280 |
+
|
281 |
print("infer: started")
|
282 |
|
283 |
p1 = pm["p"]
|
284 |
+
name = generate_random_string[32,32](12)+".png"
|
285 |
|
286 |
neg = pm["n"]
|
287 |
if neg != "":
|
|
|
294 |
|
295 |
if pm["i"] == None:
|
296 |
return None
|
297 |
+
out = Piper[32,32](pm["i"],posi,neg,pm["m"])
|
298 |
export_to_gif(out.frames[0],name,fps=fps)
|
299 |
return name
|
300 |
|
|
|
303 |
# @cpu2(cache=True,nopython=True,parallel=True)
|
304 |
# @cpu1(cache=True)
|
305 |
# @cpu2(cache=True)
|
306 |
+
def handle(*args):
|
307 |
tx = cuda.threadIdx.x
|
308 |
bx = cuda.blockIdx.x
|
309 |
dx = cuda.blockDim.x
|
310 |
pos = tx + bx * dx
|
311 |
|
312 |
+
i,m,p1,p2,*result=*args
|
313 |
+
|
314 |
+
p1_en = translate[32,32](p1,"english")
|
315 |
+
p2_en = translate[32,32](p2,"english")
|
316 |
pm = {"p":p1_en,"n":p2_en,"m":m,"i":i}
|
317 |
ln = len(result)
|
318 |
rng = list(range(ln))
|
319 |
arr = [pm for _ in rng]
|
320 |
#with Pool(f'{ ln }:ppn=2', queue='productionQ', timelimit='5:00:00', workdir='.') as pool:
|
321 |
#return pool.map(infer,arr)
|
322 |
+
ret = infer[32+ln,32](pm)
|
|
|
|
|
323 |
return ret
|
324 |
|
325 |
@gpu(cache=True)
|
|
|
381 |
|
382 |
gr.on(
|
383 |
triggers=[run_button.click, prompt.submit, prompt2.submit],
|
384 |
+
fn=handle[32,32],inputs=[img,motion,prompt,prompt2,*result],outputs=result
|
385 |
)
|
386 |
demo.queue().launch()
|
387 |
|