Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,7 @@ def Piper(_do):
|
|
| 84 |
_do,
|
| 85 |
height=448,
|
| 86 |
width=448,
|
| 87 |
-
num_inference_steps=
|
| 88 |
max_sequence_length=256,
|
| 89 |
guidance_scale=0
|
| 90 |
)
|
|
@@ -92,12 +92,14 @@ def Piper(_do):
|
|
| 92 |
except:
|
| 93 |
return ""
|
| 94 |
|
| 95 |
-
def infer(
|
| 96 |
name = generate_random_string(12)+".png"
|
| 97 |
-
if
|
| 98 |
-
_do = 'beautiful, playful, photographed
|
| 99 |
else:
|
| 100 |
-
_do = f'{
|
|
|
|
|
|
|
| 101 |
output = Piper(_do)
|
| 102 |
if output == "":
|
| 103 |
return output
|
|
@@ -140,6 +142,7 @@ footer {
|
|
| 140 |
js="""
|
| 141 |
function custom(){
|
| 142 |
document.querySelector("div#prompt input").setAttribute("maxlength","38")
|
|
|
|
| 143 |
}
|
| 144 |
"""
|
| 145 |
|
|
@@ -152,7 +155,14 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
| 152 |
with gr.Row():
|
| 153 |
prompt = gr.Textbox(
|
| 154 |
elem_id="prompt",
|
| 155 |
-
placeholder="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
container=False,
|
| 157 |
max_lines=1
|
| 158 |
)
|
|
@@ -165,17 +175,19 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
| 165 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
| 166 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
| 167 |
|
| 168 |
-
def _ret(idx,p1):
|
| 169 |
-
print(f'Starting {idx}
|
| 170 |
-
v = infer(p1)
|
| 171 |
-
print(f'Finished {idx}
|
| 172 |
return v
|
| 173 |
-
def _rets(p1):
|
| 174 |
p1_en = translate(p1,"english")
|
|
|
|
| 175 |
ln = len(result)
|
| 176 |
idxs = list(range(ln))
|
| 177 |
p1s = [p1_en for _ in idxs]
|
| 178 |
-
|
| 179 |
-
|
|
|
|
| 180 |
|
| 181 |
demo.queue().launch()
|
|
|
|
| 84 |
_do,
|
| 85 |
height=448,
|
| 86 |
width=448,
|
| 87 |
+
num_inference_steps=8,
|
| 88 |
max_sequence_length=256,
|
| 89 |
guidance_scale=0
|
| 90 |
)
|
|
|
|
| 92 |
except:
|
| 93 |
return ""
|
| 94 |
|
| 95 |
+
def infer(p1,p2):
|
| 96 |
name = generate_random_string(12)+".png"
|
| 97 |
+
if p1 == "":
|
| 98 |
+
_do = 'beautiful, playful, photographed, highly detailed, realistic elements, dynamic poze, deep field, vivid reasonable coloring, rough texture, high sharpness, highres, best quality, focused'
|
| 99 |
else:
|
| 100 |
+
_do = f'{ p1 }, beautiful, playful, photographed, highly detailed, realistic elements, dynamic poze, deep field, vivid reasonable coloring, rough texture, high sharpness, highres, best quality, focused'
|
| 101 |
+
if p2 != "":
|
| 102 |
+
_do = f'{_do}, anti-{p2.replace(" ","-")}!'
|
| 103 |
output = Piper(_do)
|
| 104 |
if output == "":
|
| 105 |
return output
|
|
|
|
| 142 |
js="""
|
| 143 |
function custom(){
|
| 144 |
document.querySelector("div#prompt input").setAttribute("maxlength","38")
|
| 145 |
+
document.querySelector("div#prompt2 input").setAttribute("maxlength","38")
|
| 146 |
}
|
| 147 |
"""
|
| 148 |
|
|
|
|
| 155 |
with gr.Row():
|
| 156 |
prompt = gr.Textbox(
|
| 157 |
elem_id="prompt",
|
| 158 |
+
placeholder="INCLUDE",
|
| 159 |
+
container=False,
|
| 160 |
+
max_lines=1
|
| 161 |
+
)
|
| 162 |
+
with gr.Row():
|
| 163 |
+
prompt2 = gr.Textbox(
|
| 164 |
+
elem_id="prompt2",
|
| 165 |
+
placeholder="EXCLUDE",
|
| 166 |
container=False,
|
| 167 |
max_lines=1
|
| 168 |
)
|
|
|
|
| 175 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
| 176 |
result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
|
| 177 |
|
| 178 |
+
def _ret(idx,p1,p2):
|
| 179 |
+
print(f'Starting {idx}')
|
| 180 |
+
v = infer(p1,p2)
|
| 181 |
+
print(f'Finished {idx}')
|
| 182 |
return v
|
| 183 |
+
def _rets(p1,p2):
|
| 184 |
p1_en = translate(p1,"english")
|
| 185 |
+
p2_en = translate(p2,"english")
|
| 186 |
ln = len(result)
|
| 187 |
idxs = list(range(ln))
|
| 188 |
p1s = [p1_en for _ in idxs]
|
| 189 |
+
p2s = [p2_en for _ in idxs]
|
| 190 |
+
return list(Pool(ln).imap( _ret, idxs, p1s, p2s ))
|
| 191 |
+
run_button.click(fn=_rets,inputs=[prompt,prompt2],outputs=result)
|
| 192 |
|
| 193 |
demo.queue().launch()
|