Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,21 +59,21 @@ def generate_random_string(length):
|
|
| 59 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 60 |
|
| 61 |
@spaces.GPU
|
| 62 |
-
def Piper(
|
| 63 |
return pipe(
|
| 64 |
-
|
| 65 |
height=512,
|
| 66 |
width=512,
|
| 67 |
-
negative_prompt=
|
| 68 |
num_inference_steps=400,
|
| 69 |
-
guidance_scale=
|
| 70 |
)
|
| 71 |
|
| 72 |
-
def infer(
|
| 73 |
name = generate_random_string(12)+".png"
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
image = Piper(
|
| 77 |
return name
|
| 78 |
|
| 79 |
css="""
|
|
@@ -98,18 +98,29 @@ with gr.Blocks(css=css) as demo:
|
|
| 98 |
Currently running on {power_device}.
|
| 99 |
""")
|
| 100 |
with gr.Row():
|
| 101 |
-
|
| 102 |
-
label="Prompt",
|
| 103 |
show_label=False,
|
| 104 |
max_lines=1,
|
| 105 |
-
placeholder="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
container=False,
|
| 107 |
)
|
| 108 |
run_button = gr.Button("Run", scale=0)
|
| 109 |
result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
|
| 110 |
run_button.click(
|
| 111 |
fn = infer,
|
| 112 |
-
inputs = [
|
| 113 |
outputs = [result]
|
| 114 |
)
|
| 115 |
|
|
|
|
| 59 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 60 |
|
| 61 |
@spaces.GPU
|
| 62 |
+
def Piper(_do, _dont):
|
| 63 |
return pipe(
|
| 64 |
+
_do,
|
| 65 |
height=512,
|
| 66 |
width=512,
|
| 67 |
+
negative_prompt=_dont,
|
| 68 |
num_inference_steps=400,
|
| 69 |
+
guidance_scale=10
|
| 70 |
)
|
| 71 |
|
| 72 |
+
def infer(prompt1,prompt2,prompt3):
|
| 73 |
name = generate_random_string(12)+".png"
|
| 74 |
+
_do = f'BACKGROUND: show an authentic {translate(prompt2,"english")}; FOREGROUND: be focused on a real {translate(prompt1,"english")}.'
|
| 75 |
+
_dont = f'ANY usage of {translate(prompt3,"english").upper()}...'
|
| 76 |
+
image = Piper(_do, _dont).images[0].save(name)
|
| 77 |
return name
|
| 78 |
|
| 79 |
css="""
|
|
|
|
| 98 |
Currently running on {power_device}.
|
| 99 |
""")
|
| 100 |
with gr.Row():
|
| 101 |
+
prompt2 = gr.Text(
|
|
|
|
| 102 |
show_label=False,
|
| 103 |
max_lines=1,
|
| 104 |
+
placeholder="(The Overall Scene)",
|
| 105 |
+
container=False,
|
| 106 |
+
)
|
| 107 |
+
prompt1 = gr.Text(
|
| 108 |
+
show_label=False,
|
| 109 |
+
max_lines=1,
|
| 110 |
+
placeholder="(The Main Content)",
|
| 111 |
+
container=False,
|
| 112 |
+
)
|
| 113 |
+
prompt3 = gr.Text(
|
| 114 |
+
show_label=False,
|
| 115 |
+
max_lines=1,
|
| 116 |
+
placeholder="(What Things Are Forbidden?)",
|
| 117 |
container=False,
|
| 118 |
)
|
| 119 |
run_button = gr.Button("Run", scale=0)
|
| 120 |
result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
|
| 121 |
run_button.click(
|
| 122 |
fn = infer,
|
| 123 |
+
inputs = [prompt1,prompt2,prompt3],
|
| 124 |
outputs = [result]
|
| 125 |
)
|
| 126 |
|