Hermes Bot commited on
Commit
8c01052
·
1 Parent(s): 596eed1

Add Gallery tab and load images

Browse files
Files changed (1) hide show
  1. ui/layout.py +67 -47
ui/layout.py CHANGED
@@ -1,48 +1,68 @@
1
- import os
2
- import gradio as gr
3
- from core.settings import *
4
-
5
- from .shared import txt2img_ui, img2img_ui, inpaint_ui, outpaint_ui, hires_fix_ui
6
-
7
- MAX_DYNAMIC_CONTROLS = 10
8
-
9
- def build_ui(event_handler_function):
10
- ui_components = {}
11
-
12
- with gr.Blocks() as demo:
13
- gr.Markdown("# ImageGen")
14
- gr.Markdown(
15
- "This demo is a streamlined version of the [Comfy web UI](https://github.com/RioShiina47/comfy-webui)'s [ImageGen](https://huggingface.co/spaces/RioShiina/ImageGen) functionality. "
16
- "Other spaces: [ImageGen1](https://huggingface.co/spaces/RioShiina/ImageGen1), "
17
- "[ImageGen2](https://huggingface.co/spaces/RioShiina/ImageGen2), "
18
- "[ImageGen3](https://huggingface.co/spaces/RioShiina/ImageGen3), "
19
- "[ImageGen4](https://huggingface.co/spaces/RioShiina/ImageGen4), "
20
- "[ImageGen5](https://huggingface.co/spaces/RioShiina/ImageGen5), "
21
- "[ImageGen6](https://huggingface.co/spaces/RioShiina/ImageGen6), "
22
- "[ImageGen7](https://huggingface.co/spaces/RioShiina/ImageGen7), "
23
- "[ImageGen8](https://huggingface.co/spaces/RioShiina/ImageGen8)"
24
- )
25
- with gr.Tabs(elem_id="tabs_container") as tabs:
26
- with gr.TabItem("Txt2Img", id=0):
27
- ui_components.update(txt2img_ui.create_ui())
28
-
29
- with gr.TabItem("Img2Img", id=1):
30
- ui_components.update(img2img_ui.create_ui())
31
-
32
- with gr.TabItem("Inpaint", id=2):
33
- ui_components.update(inpaint_ui.create_ui())
34
-
35
- with gr.TabItem("Outpaint", id=3):
36
- ui_components.update(outpaint_ui.create_ui())
37
-
38
- with gr.TabItem("Hires. Fix", id=4):
39
- ui_components.update(hires_fix_ui.create_ui())
40
-
41
- ui_components["tabs"] = tabs
42
- ui_components["image_gen_tabs"] = tabs
43
-
44
- 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>")
45
-
46
- event_handler_function(ui_components, demo)
47
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  return demo
 
1
+ import os
2
+ import gradio as gr
3
+ from core.settings import *
4
+
5
+ from .shared import txt2img_ui, img2img_ui, inpaint_ui, outpaint_ui, hires_fix_ui
6
+
7
+ MAX_DYNAMIC_CONTROLS = 10
8
+
9
+ def build_ui(event_handler_function):
10
+ ui_components = {}
11
+
12
+ with gr.Blocks() as demo:
13
+ gr.Markdown("# ImageGen")
14
+ gr.Markdown(
15
+ "This demo is a streamlined version of the [Comfy web UI](https://github.com/RioShiina47/comfy-webui)'s [ImageGen](https://huggingface.co/spaces/RioShiina/ImageGen) functionality. "
16
+ "Other spaces: [ImageGen1](https://huggingface.co/spaces/RioShiina/ImageGen1), "
17
+ "[ImageGen2](https://huggingface.co/spaces/RioShiina/ImageGen2), "
18
+ "[ImageGen3](https://huggingface.co/spaces/RioShiina/ImageGen3), "
19
+ "[ImageGen4](https://huggingface.co/spaces/RioShiina/ImageGen4), "
20
+ "[ImageGen5](https://huggingface.co/spaces/RioShiina/ImageGen5), "
21
+ "[ImageGen6](https://huggingface.co/spaces/RioShiina/ImageGen6), "
22
+ "[ImageGen7](https://huggingface.co/spaces/RioShiina/ImageGen7), "
23
+ "[ImageGen8](https://huggingface.co/spaces/RioShiina/ImageGen8)"
24
+ )
25
+ with gr.Tabs(elem_id="tabs_container") as tabs:
26
+ with gr.TabItem("Txt2Img", id=0):
27
+ ui_components.update(txt2img_ui.create_ui())
28
+
29
+ with gr.TabItem("Img2Img", id=1):
30
+ ui_components.update(img2img_ui.create_ui())
31
+
32
+ with gr.TabItem("Inpaint", id=2):
33
+ ui_components.update(inpaint_ui.create_ui())
34
+
35
+ with gr.TabItem("Outpaint", id=3):
36
+ ui_components.update(outpaint_ui.create_ui())
37
+
38
+ with gr.TabItem("Hires. Fix", id=4):
39
+ ui_components.update(hires_fix_ui.create_ui())
40
+
41
+ # New Gallery tab to display generated images
42
+ with gr.TabItem("Gallery", id=5):
43
+ gallery = gr.Gallery(label="Generated Images", show_label=False).style(grid=[3], height="auto")
44
+ ui_components["gallery"] = gallery
45
+
46
+ ui_components["tabs"] = tabs
47
+ ui_components["image_gen_tabs"] = tabs
48
+
49
+ 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>")
50
+
51
+ # Load gallery images on startup
52
+ def load_gallery_images():
53
+ # Resolve absolute path for the output directory
54
+ output_dir = os.path.abspath(OUTPUT_DIR)
55
+ if not os.path.isdir(output_dir):
56
+ return []
57
+ # Collect image files (common formats)
58
+ image_paths = []
59
+ for fname in sorted(os.listdir(output_dir)):
60
+ if fname.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp')):
61
+ image_paths.append(os.path.join(output_dir, fname))
62
+ return image_paths
63
+
64
+ demo.load(fn=load_gallery_images, outputs=ui_components["gallery"])
65
+
66
+ event_handler_function(ui_components, demo)
67
+
68
  return demo