Spaces:
Runtime error
Runtime error
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,20 +72,21 @@ def generate_random_string(length):
|
|
| 72 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 73 |
|
| 74 |
@spaces.GPU(duration=120)
|
| 75 |
-
def Piper(_do):
|
| 76 |
return pipe(
|
| 77 |
_do,
|
| 78 |
height=512,
|
| 79 |
width=768,
|
| 80 |
-
negative_prompt=
|
| 81 |
num_inference_steps=40,
|
| 82 |
guidance_scale=10
|
| 83 |
)
|
| 84 |
|
| 85 |
-
def infer(prompt):
|
| 86 |
name = generate_random_string(12)+".png"
|
| 87 |
_do = f'{ translate(prompt,"english") }, hot colors palette, muted colors, dynamic poze, realistic, accurate, matched, realistic details, award winning photograph, soft natural lighting, deep field, high definition, highly detailed, 8k'.lower()
|
| 88 |
-
|
|
|
|
| 89 |
return name
|
| 90 |
|
| 91 |
css="""
|
|
@@ -104,6 +105,7 @@ css="""
|
|
| 104 |
js="""
|
| 105 |
function custom(){
|
| 106 |
document.querySelector("div#prompt input").setAttribute("maxlength","38");
|
|
|
|
| 107 |
}
|
| 108 |
"""
|
| 109 |
|
|
@@ -121,7 +123,14 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
| 121 |
with gr.Row():
|
| 122 |
prompt = gr.Textbox(
|
| 123 |
elem_id="prompt",
|
| 124 |
-
placeholder="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
container=False,
|
| 126 |
rtl=True,
|
| 127 |
max_lines=1
|
|
@@ -129,14 +138,9 @@ with gr.Blocks(theme=gr.themes.Soft(),css=css,js=js) as demo:
|
|
| 129 |
with gr.Row():
|
| 130 |
run_button = gr.Button("Run")
|
| 131 |
result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
|
| 132 |
-
prompt.submit(
|
| 133 |
-
fn = infer,
|
| 134 |
-
inputs = [prompt],
|
| 135 |
-
outputs = [result]
|
| 136 |
-
)
|
| 137 |
run_button.click(
|
| 138 |
fn = infer,
|
| 139 |
-
inputs = [prompt],
|
| 140 |
outputs = [result]
|
| 141 |
)
|
| 142 |
|
|
|
|
| 72 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 73 |
|
| 74 |
@spaces.GPU(duration=120)
|
| 75 |
+
def Piper(_do,_dont):
|
| 76 |
return pipe(
|
| 77 |
_do,
|
| 78 |
height=512,
|
| 79 |
width=768,
|
| 80 |
+
negative_prompt=_dont,
|
| 81 |
num_inference_steps=40,
|
| 82 |
guidance_scale=10
|
| 83 |
)
|
| 84 |
|
| 85 |
+
def infer(prompt,prompt2):
|
| 86 |
name = generate_random_string(12)+".png"
|
| 87 |
_do = f'{ translate(prompt,"english") }, hot colors palette, muted colors, dynamic poze, realistic, accurate, matched, realistic details, award winning photograph, soft natural lighting, deep field, high definition, highly detailed, 8k'.lower()
|
| 88 |
+
_dont = f'{translate(prompt2,"english")}, ugly, deformed, disfigured, poor details, bad anatomy, labels, text, logo'
|
| 89 |
+
image = Piper(_do,_dont).images[0].save(name)
|
| 90 |
return name
|
| 91 |
|
| 92 |
css="""
|
|
|
|
| 105 |
js="""
|
| 106 |
function custom(){
|
| 107 |
document.querySelector("div#prompt input").setAttribute("maxlength","38");
|
| 108 |
+
document.querySelector("div#prompt2 input").setAttribute("maxlength","38");
|
| 109 |
}
|
| 110 |
"""
|
| 111 |
|
|
|
|
| 123 |
with gr.Row():
|
| 124 |
prompt = gr.Textbox(
|
| 125 |
elem_id="prompt",
|
| 126 |
+
placeholder="Photo Description",
|
| 127 |
+
container=False,
|
| 128 |
+
rtl=True,
|
| 129 |
+
max_lines=1
|
| 130 |
+
)
|
| 131 |
+
prompt2 = gr.Textbox(
|
| 132 |
+
elem_id="prompt2",
|
| 133 |
+
placeholder="Forbidden Content",
|
| 134 |
container=False,
|
| 135 |
rtl=True,
|
| 136 |
max_lines=1
|
|
|
|
| 138 |
with gr.Row():
|
| 139 |
run_button = gr.Button("Run")
|
| 140 |
result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
run_button.click(
|
| 142 |
fn = infer,
|
| 143 |
+
inputs = [prompt,prompt2],
|
| 144 |
outputs = [result]
|
| 145 |
)
|
| 146 |
|