Spaces:
Running
on
Zero
Running
on
Zero
ability to set sizes and cancel
Browse files
app.py
CHANGED
|
@@ -27,8 +27,9 @@ DEFAULT_NEGATIVE_PROMPT = None
|
|
| 27 |
@spaces.GPU
|
| 28 |
def infer(
|
| 29 |
prompt=None,
|
| 30 |
-
#ref=None,
|
| 31 |
seed=0,
|
|
|
|
|
|
|
| 32 |
text_cfg=7.5,
|
| 33 |
img_cfg=1.0,
|
| 34 |
num_inference_steps=28,
|
|
@@ -36,17 +37,12 @@ def infer(
|
|
| 36 |
negative_prompt=DEFAULT_NEGATIVE_PROMPT,
|
| 37 |
progress=gr.Progress(track_tqdm=True),
|
| 38 |
):
|
| 39 |
-
#if ref is None:
|
| 40 |
-
# gr.Warning("⚠️ Please upload an image!")
|
| 41 |
-
# return None
|
| 42 |
-
|
| 43 |
if prompt in [None, ""]:
|
| 44 |
gr.Warning("⚠️ Please enter a prompt!")
|
| 45 |
return None
|
| 46 |
-
IMG_SIZE = 512
|
| 47 |
image = pipeline.generate_image(
|
| 48 |
editing_caption,
|
| 49 |
-
hw=(
|
| 50 |
num_images_per_caption=1,
|
| 51 |
positive_prompt=positive_prompt,
|
| 52 |
negative_prompt=negative_prompt,
|
|
@@ -85,10 +81,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 85 |
editing_caption = prompt
|
| 86 |
|
| 87 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
|
|
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
-
#ref = gr.Image(label="Reference Image", show_label=True, type="pil", height=400)
|
| 91 |
-
|
| 92 |
with gr.Accordion("Advanced Settings", open=True):
|
| 93 |
positive_prompt = gr.Text(
|
| 94 |
label="Positive Prompt",
|
|
@@ -113,45 +108,45 @@ with gr.Blocks(css=css) as demo:
|
|
| 113 |
value=3407,
|
| 114 |
)
|
| 115 |
num_inference_steps = gr.Slider(
|
| 116 |
-
label="
|
| 117 |
minimum=10,
|
| 118 |
maximum=50,
|
| 119 |
step=1,
|
| 120 |
-
value=28,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
-
|
| 123 |
-
#with gr.Row():
|
| 124 |
-
#text_cfg = gr.Slider(
|
| 125 |
-
# label="Text cfg",
|
| 126 |
-
# minimum=1.0,
|
| 127 |
-
# maximum=15.0,
|
| 128 |
-
# step=0.1,
|
| 129 |
-
# value=7.5, # Replace with defaults that work for your model
|
| 130 |
-
#)
|
| 131 |
-
#img_cfg = gr.Slider(
|
| 132 |
-
# label="Image cfg",
|
| 133 |
-
# minimum=1.0,
|
| 134 |
-
# maximum=15.0,
|
| 135 |
-
# step=0.1,
|
| 136 |
-
# value=1.0,
|
| 137 |
-
#)
|
| 138 |
|
| 139 |
with gr.Row():
|
| 140 |
result_1 = gr.Image(label="Result 1", show_label=False, container=True, height=400, visible=False)
|
| 141 |
-
#result_2 = gr.Image(label="Result 2", show_label=False, container=True, height=400, visible=False)
|
| 142 |
|
| 143 |
#gr.Examples(examples=examples, inputs=[prompt, ref])
|
| 144 |
|
| 145 |
def show_result():
|
| 146 |
return gr.update(visible=True)
|
| 147 |
|
| 148 |
-
gr.on(
|
| 149 |
triggers=[run_button.click, prompt.submit],
|
| 150 |
fn=infer,
|
| 151 |
inputs=[
|
| 152 |
prompt,
|
| 153 |
-
#ref,
|
| 154 |
seed,
|
|
|
|
|
|
|
| 155 |
text_cfg,
|
| 156 |
img_cfg,
|
| 157 |
num_inference_steps,
|
|
@@ -160,6 +155,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 160 |
],
|
| 161 |
outputs=[result_1],
|
| 162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
gr.on(
|
| 165 |
triggers=[run_button.click, prompt.submit],
|
|
|
|
| 27 |
@spaces.GPU
|
| 28 |
def infer(
|
| 29 |
prompt=None,
|
|
|
|
| 30 |
seed=0,
|
| 31 |
+
width=512,
|
| 32 |
+
height=512,
|
| 33 |
text_cfg=7.5,
|
| 34 |
img_cfg=1.0,
|
| 35 |
num_inference_steps=28,
|
|
|
|
| 37 |
negative_prompt=DEFAULT_NEGATIVE_PROMPT,
|
| 38 |
progress=gr.Progress(track_tqdm=True),
|
| 39 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if prompt in [None, ""]:
|
| 41 |
gr.Warning("⚠️ Please enter a prompt!")
|
| 42 |
return None
|
|
|
|
| 43 |
image = pipeline.generate_image(
|
| 44 |
editing_caption,
|
| 45 |
+
hw=(height, width),
|
| 46 |
num_images_per_caption=1,
|
| 47 |
positive_prompt=positive_prompt,
|
| 48 |
negative_prompt=negative_prompt,
|
|
|
|
| 81 |
editing_caption = prompt
|
| 82 |
|
| 83 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 84 |
+
cancel_button = gr.Button("Cancel", scale=0, variant="secondary")
|
| 85 |
|
| 86 |
with gr.Row():
|
|
|
|
|
|
|
| 87 |
with gr.Accordion("Advanced Settings", open=True):
|
| 88 |
positive_prompt = gr.Text(
|
| 89 |
label="Positive Prompt",
|
|
|
|
| 108 |
value=3407,
|
| 109 |
)
|
| 110 |
num_inference_steps = gr.Slider(
|
| 111 |
+
label="Sampling steps",
|
| 112 |
minimum=10,
|
| 113 |
maximum=50,
|
| 114 |
step=1,
|
| 115 |
+
value=28,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
with gr.Row():
|
| 119 |
+
width = gr.Slider(
|
| 120 |
+
label="Width",
|
| 121 |
+
minimum=256,
|
| 122 |
+
maximum=1024,
|
| 123 |
+
step=64,
|
| 124 |
+
value=512,
|
| 125 |
+
)
|
| 126 |
+
height = gr.Slider(
|
| 127 |
+
label="Height",
|
| 128 |
+
minimum=256,
|
| 129 |
+
maximum=1024,
|
| 130 |
+
step=64,
|
| 131 |
+
value=512,
|
| 132 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
with gr.Row():
|
| 135 |
result_1 = gr.Image(label="Result 1", show_label=False, container=True, height=400, visible=False)
|
|
|
|
| 136 |
|
| 137 |
#gr.Examples(examples=examples, inputs=[prompt, ref])
|
| 138 |
|
| 139 |
def show_result():
|
| 140 |
return gr.update(visible=True)
|
| 141 |
|
| 142 |
+
generation_event = gr.on(
|
| 143 |
triggers=[run_button.click, prompt.submit],
|
| 144 |
fn=infer,
|
| 145 |
inputs=[
|
| 146 |
prompt,
|
|
|
|
| 147 |
seed,
|
| 148 |
+
width,
|
| 149 |
+
height,
|
| 150 |
text_cfg,
|
| 151 |
img_cfg,
|
| 152 |
num_inference_steps,
|
|
|
|
| 155 |
],
|
| 156 |
outputs=[result_1],
|
| 157 |
)
|
| 158 |
+
|
| 159 |
+
cancel_button.click(
|
| 160 |
+
fn=None,
|
| 161 |
+
inputs=None,
|
| 162 |
+
outputs=None,
|
| 163 |
+
cancels=[generation_event]
|
| 164 |
+
)
|
| 165 |
|
| 166 |
gr.on(
|
| 167 |
triggers=[run_button.click, prompt.submit],
|