Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -306,104 +306,84 @@ def extract_png_info(image_path):
|
|
306 |
return metadata
|
307 |
|
308 |
# Define the Gradio interface
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
with gr.
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
lines=5
|
321 |
-
)
|
322 |
-
batch_count = gr.Slider(minimum=1, maximum=10, step=1, label="Batch Count", value=1)
|
323 |
-
use_controlnet = gr.Checkbox(label="Use ControlNet", value=False)
|
324 |
-
controlnet_type = gr.Dropdown(choices=["Canny", "Depth", "OpenPose", "Reference"], label="ControlNet Type")
|
325 |
-
controlnet_status = gr.Textbox(label="ControlNet Status", value="", interactive=False)
|
326 |
-
mode = gr.Radio(choices=["Single Image", "Batch"], label="Mode", value="Single Image")
|
327 |
-
|
328 |
-
with gr.Tabs() as tabs:
|
329 |
-
with gr.TabItem("Single Image"):
|
330 |
-
control_image = gr.Image(label="Control Image", type='pil')
|
331 |
-
|
332 |
-
with gr.TabItem("Batch"):
|
333 |
-
batch_images_input = gr.File(label="Upload Images", file_count='multiple')
|
334 |
-
|
335 |
-
with gr.TabItem("Extract Metadata"):
|
336 |
-
png_image = gr.Image(label="Upload PNG Image", type='pil')
|
337 |
-
metadata_output = gr.JSON(label="PNG Metadata")
|
338 |
-
|
339 |
-
with gr.Column(scale=2):
|
340 |
-
style_images_gallery = gr.Gallery(
|
341 |
-
label="Choose a Style",
|
342 |
-
value=list(style_images.values()),
|
343 |
-
interactive=True,
|
344 |
-
elem_id="style-gallery",
|
345 |
-
columns=5,
|
346 |
-
object_fit="contain",
|
347 |
-
height=235,
|
348 |
-
allow_preview=False
|
349 |
)
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
-
|
355 |
-
style_names = list(styles.keys())
|
356 |
-
if evt.index < 0 or evt.index >= len(style_names):
|
357 |
-
raise ValueError(f"Invalid index: {evt.index}")
|
358 |
-
selected_style = style_names[evt.index]
|
359 |
-
return styles[selected_style]["prompt"], styles[selected_style]["negative_prompt"], selected_style
|
360 |
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
-
|
364 |
-
status = load_controlnet_model(controlnet_type)
|
365 |
-
return status
|
366 |
|
367 |
-
|
|
|
|
|
368 |
|
369 |
-
|
370 |
-
generate_button.click(
|
371 |
-
generate_images_with_progress,
|
372 |
-
inputs=[prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, control_image, batch_images_input],
|
373 |
-
outputs=gallery
|
374 |
-
)
|
375 |
-
|
376 |
-
metadata_button = gr.Button("Extract Metadata")
|
377 |
-
metadata_button.click(
|
378 |
-
fn=extract_png_info,
|
379 |
-
inputs=png_image,
|
380 |
-
outputs=metadata_output
|
381 |
-
)
|
382 |
|
383 |
-
|
384 |
-
|
|
|
|
|
|
|
|
|
385 |
|
386 |
-
|
|
|
|
|
|
|
|
|
|
|
387 |
|
388 |
-
|
389 |
-
|
390 |
-
valid_password = "roland"
|
391 |
-
|
392 |
-
# Create a login interface
|
393 |
-
def login(username, password):
|
394 |
-
if username == valid_username and password == valid_password:
|
395 |
-
return build_interface()
|
396 |
-
else:
|
397 |
-
return "Invalid credentials. Please try again."
|
398 |
-
|
399 |
-
login_interface = gr.Interface(
|
400 |
-
fn=login,
|
401 |
-
inputs=[gr.Textbox(label="Username"), gr.Textbox(label="Password", type="password")],
|
402 |
-
outputs="component",
|
403 |
-
live=True
|
404 |
-
)
|
405 |
|
406 |
-
#
|
407 |
if __name__ == "__main__":
|
408 |
-
|
|
|
409 |
clear_memory()
|
|
|
306 |
return metadata
|
307 |
|
308 |
# Define the Gradio interface
|
309 |
+
with gr.Blocks(auth={"user": "roland"}) as demo:
|
310 |
+
gr.Markdown("# Image Generation with Custom Prompts and Styles")
|
311 |
+
|
312 |
+
with gr.Row():
|
313 |
+
with gr.Column():
|
314 |
+
prompt = gr.Textbox(label="Prompt", lines=8, interactive=True)
|
315 |
+
with gr.Accordion("Negative Prompt (Minimize/Expand)", open=False):
|
316 |
+
negative_prompt = gr.Textbox(
|
317 |
+
label="Negative Prompt",
|
318 |
+
value="",
|
319 |
+
lines=5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
)
|
321 |
+
batch_count = gr.Slider(minimum=1, maximum=10, step=1, label="Batch Count", value=1)
|
322 |
+
use_controlnet = gr.Checkbox(label="Use ControlNet", value=False)
|
323 |
+
controlnet_type = gr.Dropdown(choices=["Canny", "Depth", "OpenPose", "Reference"], label="ControlNet Type")
|
324 |
+
controlnet_status = gr.Textbox(label="ControlNet Status", value="", interactive=False)
|
325 |
+
mode = gr.Radio(choices=["Single Image", "Batch"], label="Mode", value="Single Image")
|
326 |
+
|
327 |
+
with gr.Tabs() as tabs:
|
328 |
+
with gr.TabItem("Single Image"):
|
329 |
+
control_image = gr.Image(label="Control Image", type='pil')
|
330 |
+
|
331 |
+
with gr.TabItem("Batch"):
|
332 |
+
batch_images_input = gr.File(label="Upload Images", file_count='multiple')
|
333 |
+
|
334 |
+
with gr.TabItem("Extract Metadata"):
|
335 |
+
png_image = gr.Image(label="Upload PNG Image", type='pil')
|
336 |
+
metadata_output = gr.JSON(label="PNG Metadata")
|
337 |
+
|
338 |
+
with gr.Column(scale=2):
|
339 |
+
style_images_gallery = gr.Gallery(
|
340 |
+
label="Choose a Style",
|
341 |
+
value=list(style_images.values()),
|
342 |
+
interactive=True,
|
343 |
+
elem_id="style-gallery",
|
344 |
+
columns=5,
|
345 |
+
object_fit="contain",
|
346 |
+
height=235,
|
347 |
+
allow_preview=False
|
348 |
+
)
|
349 |
+
gallery = gr.Gallery(label="Generated Images", show_label=False, elem_id="gallery", height=785)
|
350 |
|
351 |
+
selected_style = gr.State(value="Anime Studio Dance")
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
+
def select_style(evt: gr.SelectData):
|
354 |
+
style_names = list(styles.keys())
|
355 |
+
if evt.index < 0 or evt.index >= len(style_names):
|
356 |
+
raise ValueError(f"Invalid index: {evt.index}")
|
357 |
+
selected_style = style_names[evt.index]
|
358 |
+
return styles[selected_style]["prompt"], styles[selected_style]["negative_prompt"], selected_style
|
359 |
|
360 |
+
style_images_gallery.select(fn=select_style, inputs=[], outputs=[prompt, negative_prompt, selected_style])
|
|
|
|
|
361 |
|
362 |
+
def update_controlnet(controlnet_type):
|
363 |
+
status = load_controlnet_model(controlnet_type)
|
364 |
+
return status
|
365 |
|
366 |
+
controlnet_type.change(fn=update_controlnet, inputs=controlnet_type, outputs=controlnet_status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
|
368 |
+
generate_button = gr.Button("Generate Images")
|
369 |
+
generate_button.click(
|
370 |
+
generate_images_with_progress,
|
371 |
+
inputs=[prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, control_image, batch_images_input],
|
372 |
+
outputs=gallery
|
373 |
+
)
|
374 |
|
375 |
+
metadata_button = gr.Button("Extract Metadata")
|
376 |
+
metadata_button.click(
|
377 |
+
fn=extract_png_info,
|
378 |
+
inputs=png_image,
|
379 |
+
outputs=metadata_output
|
380 |
+
)
|
381 |
|
382 |
+
with gr.Row():
|
383 |
+
generate_button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
|
385 |
+
# At the end of your script:
|
386 |
if __name__ == "__main__":
|
387 |
+
# Your Gradio interface setup here
|
388 |
+
demo.launch(debug=True)
|
389 |
clear_memory()
|