Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,11 +29,7 @@ def port_inc():
|
|
29 |
else:
|
30 |
os.environ["CUSTOM_PORT"]=str(int(env)+1)
|
31 |
|
32 |
-
def init_pool(
|
33 |
-
global infer1
|
34 |
-
global infer2
|
35 |
-
infer1 = _1
|
36 |
-
infer2 = _2
|
37 |
port_inc()
|
38 |
|
39 |
def pipe_t2i():
|
@@ -90,7 +86,7 @@ def generate_random_string(length):
|
|
90 |
characters = string.ascii_letters + string.digits
|
91 |
return ''.join(random.choice(characters) for _ in range(length))
|
92 |
|
93 |
-
@spaces.GPU(duration=
|
94 |
def Piper1(pipe,_do):
|
95 |
try:
|
96 |
retu = pipe(
|
@@ -106,7 +102,7 @@ def Piper1(pipe,_do):
|
|
106 |
print(e)
|
107 |
return None
|
108 |
|
109 |
-
@spaces.GPU(duration=
|
110 |
def Piper2(pipe,img,posi,neg):
|
111 |
try:
|
112 |
retu = pipe(
|
@@ -119,39 +115,12 @@ def Piper2(pipe,img,posi,neg):
|
|
119 |
print(e)
|
120 |
return None
|
121 |
|
122 |
-
@spaces.GPU(duration=
|
123 |
def tok(pipe,txt):
|
124 |
toks = pipe.tokenizer(txt)['input_ids']
|
125 |
print(toks)
|
126 |
return toks
|
127 |
|
128 |
-
def infer(p):
|
129 |
-
p1 = p["a"]
|
130 |
-
p2 = p["b"]
|
131 |
-
name = generate_random_string(12)+".png"
|
132 |
-
_do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
|
133 |
-
if p1 != "":
|
134 |
-
_do.append(f'{p1}')
|
135 |
-
if p2 != "":
|
136 |
-
_dont = f'{p2} where in {p1}'
|
137 |
-
neg = _dont
|
138 |
-
else:
|
139 |
-
neg = None
|
140 |
-
output = Piper1(infer1,'A '+" ".join(_do))
|
141 |
-
if output == None:
|
142 |
-
return None
|
143 |
-
else:
|
144 |
-
output.images[0].save(name)
|
145 |
-
if neg == None:
|
146 |
-
return name
|
147 |
-
img = load_image(name).convert("RGB")
|
148 |
-
output2 = Piper2(infer2,img,p1,neg)
|
149 |
-
if output2 == None:
|
150 |
-
return None
|
151 |
-
else:
|
152 |
-
output2.images[0].save("_"+name)
|
153 |
-
return "_"+name
|
154 |
-
|
155 |
css="""
|
156 |
input, input::placeholder {
|
157 |
text-align: center !important;
|
@@ -197,6 +166,33 @@ def main():
|
|
197 |
pp2=pipe_i2i()
|
198 |
|
199 |
result = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
def run(p1,p2,*result):
|
202 |
p1_en = translate(p1,"english")
|
@@ -206,7 +202,7 @@ def main():
|
|
206 |
rng = list(range(ln))
|
207 |
arr = [p for _ in rng]
|
208 |
out = None
|
209 |
-
with Pool(ln, initializer=init_pool
|
210 |
out = pool.imap(infer,arr)
|
211 |
return list(out)
|
212 |
port_inc()
|
|
|
29 |
else:
|
30 |
os.environ["CUSTOM_PORT"]=str(int(env)+1)
|
31 |
|
32 |
+
def init_pool():
|
|
|
|
|
|
|
|
|
33 |
port_inc()
|
34 |
|
35 |
def pipe_t2i():
|
|
|
86 |
characters = string.ascii_letters + string.digits
|
87 |
return ''.join(random.choice(characters) for _ in range(length))
|
88 |
|
89 |
+
@spaces.GPU(duration=40)
|
90 |
def Piper1(pipe,_do):
|
91 |
try:
|
92 |
retu = pipe(
|
|
|
102 |
print(e)
|
103 |
return None
|
104 |
|
105 |
+
@spaces.GPU(duration=40)
|
106 |
def Piper2(pipe,img,posi,neg):
|
107 |
try:
|
108 |
retu = pipe(
|
|
|
115 |
print(e)
|
116 |
return None
|
117 |
|
118 |
+
@spaces.GPU(duration=40)
|
119 |
def tok(pipe,txt):
|
120 |
toks = pipe.tokenizer(txt)['input_ids']
|
121 |
print(toks)
|
122 |
return toks
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
css="""
|
125 |
input, input::placeholder {
|
126 |
text-align: center !important;
|
|
|
166 |
pp2=pipe_i2i()
|
167 |
|
168 |
result = []
|
169 |
+
|
170 |
+
def infer(p):
|
171 |
+
p1 = p["a"]
|
172 |
+
p2 = p["b"]
|
173 |
+
name = generate_random_string(12)+".png"
|
174 |
+
_do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
|
175 |
+
if p1 != "":
|
176 |
+
_do.append(f'{p1}')
|
177 |
+
if p2 != "":
|
178 |
+
_dont = f'{p2} where in {p1}'
|
179 |
+
neg = _dont
|
180 |
+
else:
|
181 |
+
neg = None
|
182 |
+
output = Piper1(pp1,'A '+" ".join(_do))
|
183 |
+
if output == None:
|
184 |
+
return None
|
185 |
+
else:
|
186 |
+
output.images[0].save(name)
|
187 |
+
if neg == None:
|
188 |
+
return name
|
189 |
+
img = load_image(name).convert("RGB")
|
190 |
+
output2 = Piper2(pp2,img,p1,neg)
|
191 |
+
if output2 == None:
|
192 |
+
return None
|
193 |
+
else:
|
194 |
+
output2.images[0].save("_"+name)
|
195 |
+
return "_"+name
|
196 |
|
197 |
def run(p1,p2,*result):
|
198 |
p1_en = translate(p1,"english")
|
|
|
202 |
rng = list(range(ln))
|
203 |
arr = [p for _ in rng]
|
204 |
out = None
|
205 |
+
with Pool(ln, initializer=init_pool) as pool:
|
206 |
out = pool.imap(infer,arr)
|
207 |
return list(out)
|
208 |
port_inc()
|