Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -83,28 +83,28 @@ def generate_random_string(length):
|
|
83 |
characters = string.ascii_letters + string.digits
|
84 |
return ''.join(random.choice(characters) for _ in range(length))
|
85 |
|
86 |
-
@spaces.GPU(duration=
|
87 |
-
def
|
88 |
-
print("starting
|
89 |
-
|
90 |
-
|
|
|
91 |
height=512,
|
92 |
width=512,
|
93 |
num_inference_steps=4,
|
94 |
max_sequence_length=256,
|
95 |
guidance_scale=0
|
96 |
)
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
retu = pp2(
|
103 |
prompt=posi,
|
104 |
negative_prompt=neg,
|
105 |
image=img
|
106 |
)
|
107 |
-
|
108 |
|
109 |
def tok(pipe,txt):
|
110 |
toks = pipe.tokenizer(txt)['input_ids']
|
@@ -150,39 +150,28 @@ function custom(){
|
|
150 |
}
|
151 |
"""
|
152 |
|
153 |
-
def
|
154 |
-
print("
|
|
|
155 |
p1 = p["a"]
|
156 |
-
print(f'prompt 1: {p1}')
|
157 |
p2 = p["b"]
|
158 |
-
print(f'prompt 2: {p2}')
|
159 |
name = generate_random_string(12)+".png"
|
160 |
-
|
|
|
161 |
_do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
|
162 |
if p1 != "":
|
163 |
_do.append(f'{p1}')
|
164 |
posi = " ".join(_do)
|
165 |
-
print(posi)
|
166 |
-
output = Piper1(posi)
|
167 |
-
output.images[0].save(name)
|
168 |
-
return name
|
169 |
|
170 |
-
|
171 |
-
print("infer2: started")
|
172 |
-
p1 = p["a"]
|
173 |
-
p2 = p["b"]
|
174 |
-
name = p["c"]
|
175 |
if p2 != "":
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
output2 = Piper2(img,p1,neg)
|
182 |
-
output2.images[0].save("_"+name)
|
183 |
-
return "_"+name
|
184 |
|
185 |
-
def
|
186 |
|
187 |
p1_en = translate(p1,"english")
|
188 |
p2_en = translate(p2,"english")
|
@@ -193,31 +182,13 @@ def run1(p1,p2,*result):
|
|
193 |
|
194 |
arr = [p for _ in rng]
|
195 |
pool = Pool(ln)
|
196 |
-
out = list(pool.imap(
|
197 |
pool.close()
|
198 |
pool.join()
|
199 |
pool.clear()
|
200 |
|
201 |
return out
|
202 |
|
203 |
-
def run2(p1,p2,*result):
|
204 |
-
|
205 |
-
p1_en = translate(p1,"english")
|
206 |
-
p2_en = translate(p2,"english")
|
207 |
-
p = {"a":p1_en,"b":p2_en}
|
208 |
-
ln = len(result)
|
209 |
-
print("images: "+str(ln))
|
210 |
-
rng = list(range(ln))
|
211 |
-
|
212 |
-
arr = [{"a":p1_en,"b":p2_en,"c":result[_]} for _ in rng]
|
213 |
-
pool = Pool(ln)
|
214 |
-
out = list(pool.imap(infer2,arr))
|
215 |
-
pool.close()
|
216 |
-
pool.join()
|
217 |
-
pool.clear()
|
218 |
-
|
219 |
-
return out
|
220 |
-
|
221 |
def main():
|
222 |
|
223 |
global result
|
@@ -255,7 +226,7 @@ def main():
|
|
255 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
256 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
257 |
|
258 |
-
run_button.click(fn=
|
259 |
demo.queue().launch()
|
260 |
|
261 |
if __name__ == "__main__":
|
|
|
83 |
characters = string.ascii_letters + string.digits
|
84 |
return ''.join(random.choice(characters) for _ in range(length))
|
85 |
|
86 |
+
@spaces.GPU(duration=75,enable_queue=True)
|
87 |
+
def Piper(name,name2,posi,neg):
|
88 |
+
print("starting piper")
|
89 |
+
|
90 |
+
ret1 = pp1(
|
91 |
+
posi,
|
92 |
height=512,
|
93 |
width=512,
|
94 |
num_inference_steps=4,
|
95 |
max_sequence_length=256,
|
96 |
guidance_scale=0
|
97 |
)
|
98 |
+
ret1.images[0].save(name)
|
99 |
+
|
100 |
+
img = load_image(name).convert("RGB")
|
101 |
+
|
102 |
+
ret2 = pp2(
|
|
|
103 |
prompt=posi,
|
104 |
negative_prompt=neg,
|
105 |
image=img
|
106 |
)
|
107 |
+
ret2.images[0].save(name2)
|
108 |
|
109 |
def tok(pipe,txt):
|
110 |
toks = pipe.tokenizer(txt)['input_ids']
|
|
|
150 |
}
|
151 |
"""
|
152 |
|
153 |
+
def infer(p):
|
154 |
+
print("infer: started")
|
155 |
+
|
156 |
p1 = p["a"]
|
|
|
157 |
p2 = p["b"]
|
|
|
158 |
name = generate_random_string(12)+".png"
|
159 |
+
name2 = "_"+name
|
160 |
+
|
161 |
_do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
|
162 |
if p1 != "":
|
163 |
_do.append(f'{p1}')
|
164 |
posi = " ".join(_do)
|
|
|
|
|
|
|
|
|
165 |
|
166 |
+
neg = " "
|
|
|
|
|
|
|
|
|
167 |
if p2 != "":
|
168 |
+
neg = f'{p2} where in {p1}'
|
169 |
+
|
170 |
+
Piper(name,name2,posi,neg)
|
171 |
+
|
172 |
+
return name2
|
|
|
|
|
|
|
173 |
|
174 |
+
def run(p1,p2,*result):
|
175 |
|
176 |
p1_en = translate(p1,"english")
|
177 |
p2_en = translate(p2,"english")
|
|
|
182 |
|
183 |
arr = [p for _ in rng]
|
184 |
pool = Pool(ln)
|
185 |
+
out = list(pool.imap(infer,arr))
|
186 |
pool.close()
|
187 |
pool.join()
|
188 |
pool.clear()
|
189 |
|
190 |
return out
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
def main():
|
193 |
|
194 |
global result
|
|
|
226 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
227 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
228 |
|
229 |
+
run_button.click(fn=run,inputs=[prompt,prompt2,*result],outputs=result)
|
230 |
demo.queue().launch()
|
231 |
|
232 |
if __name__ == "__main__":
|