Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -160,46 +160,130 @@ def generate(
|
|
160 |
print(image_paths)
|
161 |
return image_paths, seed
|
162 |
|
163 |
-
# Example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
|
|
165 |
with gr.Blocks() as demo:
|
166 |
gr.Markdown(DESCRIPTION)
|
167 |
-
with gr.Row():
|
168 |
-
with gr.
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
fn=generate,
|
189 |
-
inputs=
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
outputs=result
|
|
|
203 |
)
|
204 |
|
205 |
if __name__ == "__main__":
|
|
|
160 |
print(image_paths)
|
161 |
return image_paths, seed
|
162 |
|
163 |
+
# Example prompts
|
164 |
+
examples = [
|
165 |
+
"A Monkey with a happy face in the Sahara desert.",
|
166 |
+
"Eiffel Tower was Made up of ICE.",
|
167 |
+
"Color photo of a corgi made of transparent glass, standing on the riverside in Yosemite National Park.",
|
168 |
+
"A close-up photo of a woman. She wore a blue coat with a gray dress underneath and has blue eyes.",
|
169 |
+
"A litter of golden retriever puppies playing in the snow. Their heads pop out of the snow, covered in.",
|
170 |
+
"an astronaut sitting in a diner, eating fries, cinematic, analog film",
|
171 |
+
]
|
172 |
+
|
173 |
+
# Initialize dictionaries for dynamic UI components
|
174 |
+
color_checkboxes = {}
|
175 |
+
color_sliders = {}
|
176 |
|
177 |
+
# Set up the Gradio interface
|
178 |
with gr.Blocks() as demo:
|
179 |
gr.Markdown(DESCRIPTION)
|
180 |
+
with gr.Row(equal_height=False):
|
181 |
+
with gr.Group():
|
182 |
+
with gr.Row():
|
183 |
+
prompt = gr.Text(
|
184 |
+
label="Prompt",
|
185 |
+
show_label=False,
|
186 |
+
max_lines=1,
|
187 |
+
placeholder="Enter your prompt",
|
188 |
+
container=False,
|
189 |
+
)
|
190 |
+
run_button = gr.Button("Run", scale=0)
|
191 |
+
result = gr.Gallery(label="Result", columns=NUM_IMAGES_PER_PROMPT, show_label=False)
|
192 |
+
|
193 |
+
with gr.Accordion("Color Influences", open=False):
|
194 |
+
with gr.Group():
|
195 |
+
for color in color_attributes:
|
196 |
+
with gr.Row():
|
197 |
+
color_checkboxes[color] = gr.Checkbox(label=f"{color} Selected", value=False)
|
198 |
+
color_sliders[color] = gr.Slider(label=f"{color} Influence Ratio", minimum=0, maximum=1, step=0.01, value=0)
|
199 |
+
|
200 |
+
with gr.Accordion("Advanced options", open=False):
|
201 |
+
with gr.Group():
|
202 |
+
with gr.Row():
|
203 |
+
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False, visible=True)
|
204 |
+
negative_prompt = gr.Text(
|
205 |
+
label="Negative prompt",
|
206 |
+
max_lines=1,
|
207 |
+
placeholder="Enter a negative prompt",
|
208 |
+
visible=True,
|
209 |
+
)
|
210 |
+
style_selection = gr.Radio(
|
211 |
+
show_label=True,
|
212 |
+
container=True,
|
213 |
+
interactive=True,
|
214 |
+
choices=STYLE_NAMES,
|
215 |
+
value=DEFAULT_STYLE_NAME,
|
216 |
+
label="Image Style",
|
217 |
+
)
|
218 |
+
seed = gr.Slider(
|
219 |
+
label="Seed",
|
220 |
+
minimum=0,
|
221 |
+
maximum=MAX_SEED,
|
222 |
+
step=1,
|
223 |
+
value=0,
|
224 |
+
)
|
225 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
226 |
+
with gr.Row(visible=True):
|
227 |
+
width = gr.Slider(
|
228 |
+
label="Width",
|
229 |
+
minimum=256,
|
230 |
+
maximum=MAX_IMAGE_SIZE,
|
231 |
+
step=32,
|
232 |
+
value=1024,
|
233 |
+
)
|
234 |
+
height = gr.Slider(
|
235 |
+
label="Height",
|
236 |
+
minimum=256,
|
237 |
+
maximum=MAX_IMAGE_SIZE,
|
238 |
+
step=32,
|
239 |
+
value=1024,
|
240 |
+
)
|
241 |
+
with gr.Row():
|
242 |
+
inference_steps = gr.Slider(
|
243 |
+
label="Steps",
|
244 |
+
minimum=4,
|
245 |
+
maximum=20,
|
246 |
+
step=1,
|
247 |
+
value=4,
|
248 |
+
)
|
249 |
+
|
250 |
+
gr.Examples(
|
251 |
+
examples=examples,
|
252 |
+
inputs=prompt,
|
253 |
+
outputs=[result, seed],
|
254 |
+
fn=generate,
|
255 |
+
cache_examples=CACHE_EXAMPLES,
|
256 |
+
)
|
257 |
+
|
258 |
+
use_negative_prompt.change(
|
259 |
+
fn=lambda x: gr.update(visible=x),
|
260 |
+
inputs=use_negative_prompt,
|
261 |
+
outputs=negative_prompt,
|
262 |
+
api_name=False,
|
263 |
+
)
|
264 |
+
|
265 |
+
gr.on(
|
266 |
+
triggers=[
|
267 |
+
prompt.submit,
|
268 |
+
negative_prompt.submit,
|
269 |
+
run_button.click,
|
270 |
+
],
|
271 |
fn=generate,
|
272 |
+
inputs=[
|
273 |
+
prompt,
|
274 |
+
negative_prompt,
|
275 |
+
style_selection,
|
276 |
+
use_negative_prompt,
|
277 |
+
seed,
|
278 |
+
width,
|
279 |
+
height,
|
280 |
+
inference_steps,
|
281 |
+
randomize_seed,
|
282 |
+
*[color_checkboxes[color] for color in color_attributes],
|
283 |
+
*[color_sliders[color] for color in color_attributes],
|
284 |
+
],
|
285 |
+
outputs=[result, seed],
|
286 |
+
api_name="run",
|
287 |
)
|
288 |
|
289 |
if __name__ == "__main__":
|