Commit ·
b0c0c9b
1
Parent(s): 4d18b32
Remove duplicate load_gallery_images definition to fix UnboundLocalError
Browse files- ui/layout.py +12 -13
ui/layout.py
CHANGED
|
@@ -9,6 +9,17 @@ MAX_DYNAMIC_CONTROLS = 10
|
|
| 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")
|
|
@@ -55,19 +66,7 @@ def build_ui(event_handler_function):
|
|
| 55 |
|
| 56 |
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>")
|
| 57 |
|
| 58 |
-
# Load gallery images on startup
|
| 59 |
-
def load_gallery_images():
|
| 60 |
-
# Resolve absolute path for the output directory
|
| 61 |
-
output_dir = os.path.abspath(OUTPUT_DIR)
|
| 62 |
-
if not os.path.isdir(output_dir):
|
| 63 |
-
return []
|
| 64 |
-
# Collect image files (common formats)
|
| 65 |
-
image_paths = []
|
| 66 |
-
for fname in sorted(os.listdir(output_dir)):
|
| 67 |
-
if fname.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp')):
|
| 68 |
-
image_paths.append(os.path.join(output_dir, fname))
|
| 69 |
-
return image_paths
|
| 70 |
-
|
| 71 |
demo.load(fn=load_gallery_images, outputs=ui_components["gallery"])
|
| 72 |
|
| 73 |
# Connect event handlers (e.g., button clicks) with the UI components.
|
|
|
|
| 9 |
def build_ui(event_handler_function):
|
| 10 |
ui_components = {}
|
| 11 |
|
| 12 |
+
# Helper function to load thumbnails from the output folder.
|
| 13 |
+
def load_gallery_images():
|
| 14 |
+
output_dir = os.path.abspath(OUTPUT_DIR)
|
| 15 |
+
if not os.path.isdir(output_dir):
|
| 16 |
+
return []
|
| 17 |
+
image_paths = []
|
| 18 |
+
for fname in sorted(os.listdir(output_dir)):
|
| 19 |
+
if fname.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
|
| 20 |
+
image_paths.append(os.path.join(output_dir, fname))
|
| 21 |
+
return image_paths
|
| 22 |
+
|
| 23 |
# All UI components, including tabs, must be created inside the same Gradio Blocks context.
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
gr.Markdown("# ImageGen")
|
|
|
|
| 66 |
|
| 67 |
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>")
|
| 68 |
|
| 69 |
+
# Load gallery images on startup using the helper defined earlier.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
demo.load(fn=load_gallery_images, outputs=ui_components["gallery"])
|
| 71 |
|
| 72 |
# Connect event handlers (e.g., button clicks) with the UI components.
|