Commit
·
d9f8976
1
Parent(s):
b6b27f8
Refactor flux_events.py to add GPU duration for image generation
Browse files- modules/events/flux_events.py +1 -1
- tabs/image_tab.py +121 -121
modules/events/flux_events.py
CHANGED
@@ -206,7 +206,7 @@ def remove_from_enabled_loras(enabled_loras, index):
|
|
206 |
)
|
207 |
|
208 |
|
209 |
-
@spaces.GPU
|
210 |
def generate_image(
|
211 |
model, prompt, fast_generation, enabled_loras,
|
212 |
lora_slider_0, lora_slider_1, lora_slider_2, lora_slider_3, lora_slider_4, lora_slider_5,
|
|
|
206 |
)
|
207 |
|
208 |
|
209 |
+
@spaces.GPU(duration=120)
|
210 |
def generate_image(
|
211 |
model, prompt, fast_generation, enabled_loras,
|
212 |
lora_slider_0, lora_slider_1, lora_slider_2, lora_slider_3, lora_slider_4, lora_slider_5,
|
tabs/image_tab.py
CHANGED
@@ -11,136 +11,137 @@ from config import flux_models, sdxl_models, flux_loras
|
|
11 |
|
12 |
def image_tab():
|
13 |
with gr.Tabs():
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
|
18 |
def flux_tab():
|
19 |
loras = flux_loras
|
20 |
-
with gr.
|
21 |
-
with gr.
|
22 |
-
with gr.
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
with gr.
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
with gr.Column():
|
41 |
with gr.Row():
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
add_lora = gr.Button(value="Add LoRA")
|
47 |
-
|
48 |
-
enabled_loras = gr.State(value=[])
|
49 |
-
with gr.Group():
|
50 |
-
with gr.Row():
|
51 |
-
for i in range(6): # only support max 6 loras due to inference time
|
52 |
with gr.Column():
|
53 |
-
|
54 |
-
globals()[f"lora_slider_{i}"] = gr.Slider(label=f"LoRA {i+1}", minimum=0, maximum=1, step=0.01, value=0.8, visible=False, interactive=True)
|
55 |
-
with gr.Column():
|
56 |
-
globals()[f"lora_remove_{i}"] = gr.Button(value="Remove LoRA", visible=False)
|
57 |
|
58 |
-
|
59 |
-
with gr.Accordion("Embeddings", open=False): # Embeddings
|
60 |
-
gr.Label("To be implemented")
|
61 |
-
|
62 |
-
|
63 |
-
with gr.Accordion("Image Options"): # Image Options
|
64 |
-
with gr.Tabs():
|
65 |
-
image_options = {
|
66 |
-
"img2img": "Upload Image",
|
67 |
-
"inpaint": "Upload Image",
|
68 |
-
"canny": "Upload Image",
|
69 |
-
"pose": "Upload Image",
|
70 |
-
"depth": "Upload Image",
|
71 |
-
}
|
72 |
-
|
73 |
-
for image_option, label in image_options.items():
|
74 |
-
with gr.Tab(image_option):
|
75 |
-
if not image_option in ['inpaint', 'scribble']:
|
76 |
-
globals()[f"{image_option}_image"] = gr.Image(label=label, type="pil")
|
77 |
-
elif image_option in ['inpaint', 'scribble']:
|
78 |
-
globals()[f"{image_option}_image"] = gr.ImageEditor(
|
79 |
-
label=label,
|
80 |
-
image_mode='RGB',
|
81 |
-
layers=False,
|
82 |
-
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed") if image_option == 'inpaint' else gr.Brush(),
|
83 |
-
interactive=True,
|
84 |
-
type="pil",
|
85 |
-
)
|
86 |
-
|
87 |
-
# Image Strength (Co-relates to controlnet strength, strength for img2img n inpaint)
|
88 |
-
globals()[f"{image_option}_strength"] = gr.Slider(label="Strength", minimum=0, maximum=1, step=0.01, value=1.0, interactive=True)
|
89 |
-
|
90 |
-
resize_mode = gr.Radio(
|
91 |
-
label="Resize Mode",
|
92 |
-
choices=["crop and resize", "resize only", "resize and fill"],
|
93 |
-
value="resize and fill",
|
94 |
-
interactive=True
|
95 |
-
)
|
96 |
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
with gr.Accordion("Advance Settings", open=True):
|
110 |
-
with gr.Row():
|
111 |
-
scheduler = gr.Dropdown(
|
112 |
-
label="Scheduler",
|
113 |
-
choices = [
|
114 |
-
"fm_euler"
|
115 |
-
],
|
116 |
-
value="fm_euler",
|
117 |
-
interactive=True
|
118 |
-
)
|
119 |
-
|
120 |
-
with gr.Row():
|
121 |
-
for column in range(2):
|
122 |
-
with gr.Column():
|
123 |
-
options = [
|
124 |
-
("Height", "image_height", 64, 1024, 64, 1024, True),
|
125 |
-
("Width", "image_width", 64, 1024, 64, 1024, True),
|
126 |
-
("Num Images Per Prompt", "image_num_images_per_prompt", 1, 4, 1, 1, True),
|
127 |
-
("Num Inference Steps", "image_num_inference_steps", 1, 100, 1, 20, True),
|
128 |
-
("Clip Skip", "image_clip_skip", 0, 2, 1, 2, False),
|
129 |
-
("Guidance Scale", "image_guidance_scale", 0, 20, 0.5, 3.5, True),
|
130 |
-
("Seed", "image_seed", 0, 100000, 1, random.randint(0, 100000), True),
|
131 |
-
]
|
132 |
-
for label, var_name, min_val, max_val, step, value, visible in options[column::2]:
|
133 |
-
globals()[var_name] = gr.Slider(label=label, minimum=min_val, maximum=max_val, step=step, value=value, visible=visible, interactive=True)
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
# Events
|
146 |
# Base Options
|
@@ -179,5 +180,4 @@ def flux_tab():
|
|
179 |
|
180 |
|
181 |
def sdxl_tab():
|
182 |
-
|
183 |
-
gr.Label("To be implemented")
|
|
|
11 |
|
12 |
def image_tab():
|
13 |
with gr.Tabs():
|
14 |
+
with gr.Tab("Flux"):
|
15 |
+
flux_tab()
|
16 |
+
with gr.Tab("SDXL"):
|
17 |
+
sdxl_tab()
|
18 |
|
19 |
|
20 |
def flux_tab():
|
21 |
loras = flux_loras
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
with gr.Group() as image_options:
|
25 |
+
model = gr.Dropdown(label="Models", choices=flux_models, value=flux_models[0], interactive=True)
|
26 |
+
prompt = gr.Textbox(lines=5, label="Prompt")
|
27 |
+
fast_generation = gr.Checkbox(label="Fast Generation (Hyper-SD) 🧪")
|
28 |
+
|
29 |
+
|
30 |
+
with gr.Accordion("Loras", open=True): # Lora Gallery
|
31 |
+
lora_gallery = gr.Gallery(
|
32 |
+
label="Gallery",
|
33 |
+
value=[(lora['image'], lora['title']) for lora in loras],
|
34 |
+
allow_preview=False,
|
35 |
+
columns=3,
|
36 |
+
rows=3,
|
37 |
+
type="pil"
|
38 |
+
)
|
39 |
|
40 |
+
with gr.Group():
|
41 |
+
with gr.Column():
|
42 |
+
with gr.Row():
|
43 |
+
custom_lora = gr.Textbox(label="Custom Lora", info="Enter a Huggingface repo path")
|
44 |
+
selected_lora = gr.Textbox(label="Selected Lora", info="Choose from the gallery or enter a custom LoRA")
|
45 |
+
|
46 |
+
custom_lora_info = gr.HTML(visible=False)
|
47 |
+
add_lora = gr.Button(value="Add LoRA")
|
48 |
+
|
49 |
+
enabled_loras = gr.State(value=[])
|
50 |
+
with gr.Group():
|
|
|
51 |
with gr.Row():
|
52 |
+
for i in range(6): # only support max 6 loras due to inference time
|
53 |
+
with gr.Column():
|
54 |
+
with gr.Column(scale=2):
|
55 |
+
globals()[f"lora_slider_{i}"] = gr.Slider(label=f"LoRA {i+1}", minimum=0, maximum=1, step=0.01, value=0.8, visible=False, interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
with gr.Column():
|
57 |
+
globals()[f"lora_remove_{i}"] = gr.Button(value="Remove LoRA", visible=False)
|
|
|
|
|
|
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
with gr.Accordion("Embeddings", open=False): # Embeddings
|
61 |
+
gr.Label("To be implemented")
|
62 |
|
63 |
+
|
64 |
+
with gr.Accordion("Image Options", open=False): # Image Options
|
65 |
+
with gr.Tabs():
|
66 |
+
image_options = {
|
67 |
+
"img2img": "Upload Image",
|
68 |
+
"inpaint": "Upload Image",
|
69 |
+
"canny": "Upload Image",
|
70 |
+
"pose": "Upload Image",
|
71 |
+
"depth": "Upload Image",
|
72 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
for image_option, label in image_options.items():
|
75 |
+
with gr.Tab(image_option):
|
76 |
+
if not image_option in ['inpaint', 'scribble']:
|
77 |
+
globals()[f"{image_option}_image"] = gr.Image(label=label, type="pil")
|
78 |
+
elif image_option in ['inpaint', 'scribble']:
|
79 |
+
globals()[f"{image_option}_image"] = gr.ImageEditor(
|
80 |
+
label=label,
|
81 |
+
image_mode='RGB',
|
82 |
+
layers=False,
|
83 |
+
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed") if image_option == 'inpaint' else gr.Brush(),
|
84 |
+
interactive=True,
|
85 |
+
type="pil",
|
86 |
+
)
|
87 |
+
|
88 |
+
# Image Strength (Co-relates to controlnet strength, strength for img2img n inpaint)
|
89 |
+
globals()[f"{image_option}_strength"] = gr.Slider(label="Strength", minimum=0, maximum=1, step=0.01, value=1.0, interactive=True)
|
90 |
+
|
91 |
+
resize_mode = gr.Radio(
|
92 |
+
label="Resize Mode",
|
93 |
+
choices=["crop and resize", "resize only", "resize and fill"],
|
94 |
+
value="resize and fill",
|
95 |
+
interactive=True
|
96 |
+
)
|
97 |
+
|
98 |
+
|
99 |
+
with gr.Column():
|
100 |
+
with gr.Group():
|
101 |
+
output_images = gr.Gallery(
|
102 |
+
label="Output Images",
|
103 |
+
value=[],
|
104 |
+
allow_preview=True,
|
105 |
+
type="pil",
|
106 |
+
interactive=False,
|
107 |
+
)
|
108 |
+
generate_images = gr.Button(value="Generate Images", variant="primary")
|
109 |
+
|
110 |
+
with gr.Accordion("Advance Settings", open=True):
|
111 |
+
with gr.Row():
|
112 |
+
scheduler = gr.Dropdown(
|
113 |
+
label="Scheduler",
|
114 |
+
choices = [
|
115 |
+
"fm_euler"
|
116 |
+
],
|
117 |
+
value="fm_euler",
|
118 |
+
interactive=True
|
119 |
+
)
|
120 |
+
|
121 |
+
with gr.Row():
|
122 |
+
for column in range(2):
|
123 |
+
with gr.Column():
|
124 |
+
options = [
|
125 |
+
("Height", "image_height", 64, 1024, 64, 1024, True),
|
126 |
+
("Width", "image_width", 64, 1024, 64, 1024, True),
|
127 |
+
("Num Images Per Prompt", "image_num_images_per_prompt", 1, 4, 1, 1, True),
|
128 |
+
("Num Inference Steps", "image_num_inference_steps", 1, 100, 1, 20, True),
|
129 |
+
("Clip Skip", "image_clip_skip", 0, 2, 1, 2, False),
|
130 |
+
("Guidance Scale", "image_guidance_scale", 0, 20, 0.5, 3.5, True),
|
131 |
+
("Seed", "image_seed", 0, 100000, 1, random.randint(0, 100000), True),
|
132 |
+
]
|
133 |
+
for label, var_name, min_val, max_val, step, value, visible in options[column::2]:
|
134 |
+
globals()[var_name] = gr.Slider(label=label, minimum=min_val, maximum=max_val, step=step, value=value, visible=visible, interactive=True)
|
135 |
+
|
136 |
+
with gr.Row():
|
137 |
+
refiner = gr.Checkbox(
|
138 |
+
label="Refiner 🧪",
|
139 |
+
value=False,
|
140 |
+
)
|
141 |
+
vae = gr.Checkbox(
|
142 |
+
label="VAE",
|
143 |
+
value=True,
|
144 |
+
)
|
145 |
|
146 |
# Events
|
147 |
# Base Options
|
|
|
180 |
|
181 |
|
182 |
def sdxl_tab():
|
183 |
+
gr.Label("To be implemented")
|
|