Commit ·
88b1d8e
1
Parent(s): a7f4148
Fix UI nesting to resolve Dropdown page attribute error
Browse files- ui/layout.py +46 -42
ui/layout.py
CHANGED
|
@@ -9,6 +9,7 @@ MAX_DYNAMIC_CONTROLS = 10
|
|
| 9 |
def build_ui(event_handler_function):
|
| 10 |
ui_components = {}
|
| 11 |
|
|
|
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
gr.Markdown("# ImageGen")
|
| 14 |
gr.Markdown(
|
|
@@ -22,47 +23,50 @@ def build_ui(event_handler_function):
|
|
| 22 |
"[ImageGen7](https://huggingface.co/spaces/RioShiina/ImageGen7), "
|
| 23 |
"[ImageGen8](https://huggingface.co/spaces/RioShiina/ImageGen8)"
|
| 24 |
)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
return demo
|
|
|
|
| 9 |
def build_ui(event_handler_function):
|
| 10 |
ui_components = {}
|
| 11 |
|
| 12 |
+
# All UI components, including tabs, must be created inside the same Gradio Blocks context.
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
gr.Markdown("# ImageGen")
|
| 15 |
gr.Markdown(
|
|
|
|
| 23 |
"[ImageGen7](https://huggingface.co/spaces/RioShiina/ImageGen7), "
|
| 24 |
"[ImageGen8](https://huggingface.co/spaces/RioShiina/ImageGen8)"
|
| 25 |
)
|
| 26 |
+
|
| 27 |
+
# Tabs container – now correctly nested within the Blocks context.
|
| 28 |
+
with gr.Tabs(elem_id="tabs_container") as tabs:
|
| 29 |
+
with gr.TabItem("Txt2Img", id=0):
|
| 30 |
+
ui_components.update(txt2img_ui.create_ui())
|
| 31 |
+
|
| 32 |
+
with gr.TabItem("Img2Img", id=1):
|
| 33 |
+
ui_components.update(img2img_ui.create_ui())
|
| 34 |
+
|
| 35 |
+
with gr.TabItem("Inpaint", id=2):
|
| 36 |
+
ui_components.update(inpaint_ui.create_ui())
|
| 37 |
+
|
| 38 |
+
with gr.TabItem("Outpaint", id=3):
|
| 39 |
+
ui_components.update(outpaint_ui.create_ui())
|
| 40 |
+
|
| 41 |
+
with gr.TabItem("Hires. Fix", id=4):
|
| 42 |
+
ui_components.update(hires_fix_ui.create_ui())
|
| 43 |
+
|
| 44 |
+
# New Gallery tab to display generated images
|
| 45 |
+
with gr.TabItem("Gallery", id=5):
|
| 46 |
+
gallery = gr.Gallery(label="Generated Images", show_label=False).style(grid=[3], height="auto")
|
| 47 |
+
ui_components["gallery"] = gallery
|
| 48 |
+
|
| 49 |
+
ui_components["tabs"] = tabs
|
| 50 |
+
ui_components["image_gen_tabs"] = tabs
|
| 51 |
+
|
| 52 |
+
gr.Markdown("<div style='text-align: center; margin-top: 20px;'>Made by RioShiina with ❤️<br><a href='https://github.com/RioShiina47' target='_blank'>GitHub</a> | <a href='https://huggingface.co/RioShiina' target='_blank'>Hugging Face</a> | <a href='https://civitai.com/user/RioShiina' target='_blank'>Civitai</a></div>")
|
| 53 |
+
|
| 54 |
+
# Load gallery images on startup
|
| 55 |
+
def load_gallery_images():
|
| 56 |
+
# Resolve absolute path for the output directory
|
| 57 |
+
output_dir = os.path.abspath(OUTPUT_DIR)
|
| 58 |
+
if not os.path.isdir(output_dir):
|
| 59 |
+
return []
|
| 60 |
+
# Collect image files (common formats)
|
| 61 |
+
image_paths = []
|
| 62 |
+
for fname in sorted(os.listdir(output_dir)):
|
| 63 |
+
if fname.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp')):
|
| 64 |
+
image_paths.append(os.path.join(output_dir, fname))
|
| 65 |
+
return image_paths
|
| 66 |
+
|
| 67 |
+
demo.load(fn=load_gallery_images, outputs=ui_components["gallery"])
|
| 68 |
+
|
| 69 |
+
# Connect event handlers (e.g., button clicks) with the UI components.
|
| 70 |
+
event_handler_function(ui_components, demo)
|
| 71 |
|
| 72 |
return demo
|