Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
import re
|
3 |
-
import spaces
|
4 |
import random
|
5 |
import string
|
6 |
import torch
|
@@ -10,9 +10,9 @@ import numpy as np
|
|
10 |
from lxml.html import fromstring
|
11 |
#from transformers import pipeline
|
12 |
from torch import multiprocessing as mp
|
13 |
-
|
14 |
-
from pathos.multiprocessing import ProcessPool as
|
15 |
-
from pathos.threading import ThreadPool as
|
16 |
#from diffusers.pipelines.flux import FluxPipeline
|
17 |
#from diffusers.utils import export_to_gif
|
18 |
#from huggingface_hub import hf_hub_download
|
@@ -83,7 +83,7 @@ def generate_random_string(length):
|
|
83 |
characters = string.ascii_letters + string.digits
|
84 |
return ''.join(random.choice(characters) for _ in range(length))
|
85 |
|
86 |
-
@
|
87 |
def Piper1(_do):
|
88 |
print("starting piper1")
|
89 |
retu = pp1(
|
@@ -97,7 +97,7 @@ def Piper1(_do):
|
|
97 |
print("returning piper1")
|
98 |
return retu
|
99 |
|
100 |
-
@
|
101 |
def Piper2(img,posi,neg):
|
102 |
retu = pp2(
|
103 |
prompt=posi,
|
@@ -106,7 +106,6 @@ def Piper2(img,posi,neg):
|
|
106 |
)
|
107 |
return retu
|
108 |
|
109 |
-
@spaces.GPU(duration=40)
|
110 |
def tok(pipe,txt):
|
111 |
toks = pipe.tokenizer(txt)['input_ids']
|
112 |
print(toks)
|
@@ -191,14 +190,14 @@ def run(p1,p2,*result):
|
|
191 |
rng = list(range(ln))
|
192 |
|
193 |
arr1 = [p for _ in rng]
|
194 |
-
pool1 =
|
195 |
out1 = list(pool1.imap(infer1,arr1))
|
196 |
pool1.close()
|
197 |
pool1.join()
|
198 |
pool1.clear()
|
199 |
|
200 |
arr2 = [{"a":p1_en,"b":p2_en,"c":out1[_]} for _ in rng]
|
201 |
-
pool2 =
|
202 |
out2 = list(pool2.imap(infer2,arr2))
|
203 |
pool2.close()
|
204 |
pool2.join()
|
|
|
1 |
import os
|
2 |
import re
|
3 |
+
import spaces as spaces1, spaces2
|
4 |
import random
|
5 |
import string
|
6 |
import torch
|
|
|
10 |
from lxml.html import fromstring
|
11 |
#from transformers import pipeline
|
12 |
from torch import multiprocessing as mp
|
13 |
+
from torch.multiprocessing import Pool as Pool
|
14 |
+
#from pathos.multiprocessing import ProcessPool as Pool
|
15 |
+
#from pathos.threading import ThreadPool as Pool
|
16 |
#from diffusers.pipelines.flux import FluxPipeline
|
17 |
#from diffusers.utils import export_to_gif
|
18 |
#from huggingface_hub import hf_hub_download
|
|
|
83 |
characters = string.ascii_letters + string.digits
|
84 |
return ''.join(random.choice(characters) for _ in range(length))
|
85 |
|
86 |
+
@spaces1.GPU(duration=40)
|
87 |
def Piper1(_do):
|
88 |
print("starting piper1")
|
89 |
retu = pp1(
|
|
|
97 |
print("returning piper1")
|
98 |
return retu
|
99 |
|
100 |
+
@spaces2.GPU(duration=40)
|
101 |
def Piper2(img,posi,neg):
|
102 |
retu = pp2(
|
103 |
prompt=posi,
|
|
|
106 |
)
|
107 |
return retu
|
108 |
|
|
|
109 |
def tok(pipe,txt):
|
110 |
toks = pipe.tokenizer(txt)['input_ids']
|
111 |
print(toks)
|
|
|
190 |
rng = list(range(ln))
|
191 |
|
192 |
arr1 = [p for _ in rng]
|
193 |
+
pool1 = Pool(ln)
|
194 |
out1 = list(pool1.imap(infer1,arr1))
|
195 |
pool1.close()
|
196 |
pool1.join()
|
197 |
pool1.clear()
|
198 |
|
199 |
arr2 = [{"a":p1_en,"b":p2_en,"c":out1[_]} for _ in rng]
|
200 |
+
pool2 = Pool(ln)
|
201 |
out2 = list(pool2.imap(infer2,arr2))
|
202 |
pool2.close()
|
203 |
pool2.join()
|