Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,7 +79,7 @@ def inpaint(
|
|
| 79 |
return result.convert("RGBA"), prompt, seed
|
| 80 |
|
| 81 |
# ========================
|
| 82 |
-
# API
|
| 83 |
# ========================
|
| 84 |
def inpaint_api(
|
| 85 |
image,
|
|
@@ -88,8 +88,8 @@ def inpaint_api(
|
|
| 88 |
seed: int,
|
| 89 |
num_inference_steps: int,
|
| 90 |
guidance_scale: int,
|
| 91 |
-
flux_keywords:
|
| 92 |
-
loras_selected:
|
| 93 |
):
|
| 94 |
flux_keywords = flux_keywords or []
|
| 95 |
loras_selected = loras_selected or []
|
|
@@ -129,53 +129,7 @@ def inpaint_api(
|
|
| 129 |
)
|
| 130 |
|
| 131 |
# ========================
|
| 132 |
-
#
|
| 133 |
-
# ========================
|
| 134 |
-
def ui_to_api_adapter(*ui_args):
|
| 135 |
-
# Desempaquetar argumentos del UI
|
| 136 |
-
main_inputs = ui_args[:6] # image, mask, prompt, seed, steps, guidance
|
| 137 |
-
flux_keyword_values = ui_args[6:6 + len(flux_keywords_available)]
|
| 138 |
-
lora_args = ui_args[6 + len(flux_keywords_available):]
|
| 139 |
-
|
| 140 |
-
# Construir lista de keywords seleccionadas
|
| 141 |
-
flux_keywords = [
|
| 142 |
-
kw for kw, selected in zip(flux_keywords_available, flux_keyword_values) if selected
|
| 143 |
-
]
|
| 144 |
-
|
| 145 |
-
# Construir lista de (nombre, peso) para LoRAs seleccionados
|
| 146 |
-
loras_selected = []
|
| 147 |
-
for i, lora_obj in enumerate(loras):
|
| 148 |
-
enabled = lora_args[i * 2]
|
| 149 |
-
weight = lora_args[i * 2 + 1]
|
| 150 |
-
if enabled:
|
| 151 |
-
loras_selected.append((lora_obj.display_name, weight))
|
| 152 |
-
|
| 153 |
-
return inpaint_api(*main_inputs, flux_keywords=flux_keywords, loras_selected=loras_selected)
|
| 154 |
-
|
| 155 |
-
# ========================
|
| 156 |
-
# CREACIÓN DE COMPONENTES
|
| 157 |
-
# ========================
|
| 158 |
-
def toggle_input(checked):
|
| 159 |
-
return gr.Number(interactive=checked)
|
| 160 |
-
|
| 161 |
-
def create_flux_keyword_components():
|
| 162 |
-
components = []
|
| 163 |
-
for keyword in flux_keywords_available:
|
| 164 |
-
components.append(gr.Checkbox(label=keyword, value=False))
|
| 165 |
-
return components
|
| 166 |
-
|
| 167 |
-
def create_lora_components():
|
| 168 |
-
components = []
|
| 169 |
-
for lora in loras:
|
| 170 |
-
checkbox = gr.Checkbox(label=lora.display_name, value=False, info=lora.note or "")
|
| 171 |
-
number_input = gr.Number(value=0.5, minimum=-1.0, maximum=1.0, step=0.1,
|
| 172 |
-
interactive=False, label="Adapter weight")
|
| 173 |
-
checkbox.change(fn=toggle_input, inputs=[checkbox], outputs=[number_input], api_name=False)
|
| 174 |
-
components.append((checkbox, number_input))
|
| 175 |
-
return components
|
| 176 |
-
|
| 177 |
-
# ========================
|
| 178 |
-
# UI
|
| 179 |
# ========================
|
| 180 |
with gr.Blocks(title="Flux.1 Fill dev Inpainting with LoRAs", theme=gr.themes.Soft()) as demo:
|
| 181 |
with gr.Row():
|
|
@@ -187,12 +141,17 @@ with gr.Blocks(title="Flux.1 Fill dev Inpainting with LoRAs", theme=gr.themes.So
|
|
| 187 |
guidance_scale_input = gr.Number(label="Guidance scale", value=28, interactive=True)
|
| 188 |
|
| 189 |
gr.Markdown("### Flux Keywords")
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
with gr.Column(scale=3):
|
| 198 |
image_input = gr.Image(label="Image", type="pil")
|
|
@@ -204,10 +163,8 @@ with gr.Blocks(title="Flux.1 Fill dev Inpainting with LoRAs", theme=gr.themes.So
|
|
| 204 |
used_prompt_box = gr.Text(label="Used prompt", lines=4)
|
| 205 |
used_seed_box = gr.Number(label="Used seed")
|
| 206 |
|
| 207 |
-
flat_lora_components = [comp for pair in lora_components for comp in pair]
|
| 208 |
-
|
| 209 |
run_btn.click(
|
| 210 |
-
fn=
|
| 211 |
inputs=[
|
| 212 |
image_input,
|
| 213 |
mask_input,
|
|
@@ -215,7 +172,9 @@ with gr.Blocks(title="Flux.1 Fill dev Inpainting with LoRAs", theme=gr.themes.So
|
|
| 215 |
seed_slider,
|
| 216 |
num_inference_steps_input,
|
| 217 |
guidance_scale_input,
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
outputs=[result_image, used_prompt_box, used_seed_box],
|
| 220 |
api_name="inpaint"
|
| 221 |
)
|
|
|
|
| 79 |
return result.convert("RGBA"), prompt, seed
|
| 80 |
|
| 81 |
# ========================
|
| 82 |
+
# API Y UI UNIFICADAS
|
| 83 |
# ========================
|
| 84 |
def inpaint_api(
|
| 85 |
image,
|
|
|
|
| 88 |
seed: int,
|
| 89 |
num_inference_steps: int,
|
| 90 |
guidance_scale: int,
|
| 91 |
+
flux_keywords: List[str] = None,
|
| 92 |
+
loras_selected: List[Tuple[str, float]] = None
|
| 93 |
):
|
| 94 |
flux_keywords = flux_keywords or []
|
| 95 |
loras_selected = loras_selected or []
|
|
|
|
| 129 |
)
|
| 130 |
|
| 131 |
# ========================
|
| 132 |
+
# UI DIRECTA A inpaint_api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
# ========================
|
| 134 |
with gr.Blocks(title="Flux.1 Fill dev Inpainting with LoRAs", theme=gr.themes.Soft()) as demo:
|
| 135 |
with gr.Row():
|
|
|
|
| 141 |
guidance_scale_input = gr.Number(label="Guidance scale", value=28, interactive=True)
|
| 142 |
|
| 143 |
gr.Markdown("### Flux Keywords")
|
| 144 |
+
flux_keywords_input = gr.CheckboxGroup(choices=flux_keywords_available, label="Flux Keywords")
|
| 145 |
+
|
| 146 |
+
gr.Markdown("### Available LoRAs")
|
| 147 |
+
lora_names = [l.display_name for l in loras]
|
| 148 |
+
loras_selected_input = gr.Dataframe(
|
| 149 |
+
headers=["LoRA", "Weight"],
|
| 150 |
+
value=[[name, 0.5] for name in lora_names],
|
| 151 |
+
type="array",
|
| 152 |
+
interactive=True,
|
| 153 |
+
label="LoRA selection (set Weight to 0 to disable)"
|
| 154 |
+
)
|
| 155 |
|
| 156 |
with gr.Column(scale=3):
|
| 157 |
image_input = gr.Image(label="Image", type="pil")
|
|
|
|
| 163 |
used_prompt_box = gr.Text(label="Used prompt", lines=4)
|
| 164 |
used_seed_box = gr.Number(label="Used seed")
|
| 165 |
|
|
|
|
|
|
|
| 166 |
run_btn.click(
|
| 167 |
+
fn=inpaint_api,
|
| 168 |
inputs=[
|
| 169 |
image_input,
|
| 170 |
mask_input,
|
|
|
|
| 172 |
seed_slider,
|
| 173 |
num_inference_steps_input,
|
| 174 |
guidance_scale_input,
|
| 175 |
+
flux_keywords_input,
|
| 176 |
+
loras_selected_input
|
| 177 |
+
],
|
| 178 |
outputs=[result_image, used_prompt_box, used_seed_box],
|
| 179 |
api_name="inpaint"
|
| 180 |
)
|