Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
|
@@ -266,6 +266,53 @@ css = """
|
|
| 266 |
}
|
| 267 |
"""
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
with gr.Blocks(css=css) as demo:
|
| 270 |
with gr.Column(elem_id="col-container"):
|
| 271 |
gr.Markdown("# Multi-Model Image Generation")
|
|
@@ -352,54 +399,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 352 |
)
|
| 353 |
refresh_button = gr.Button("Refresh Gallery",visible=True)
|
| 354 |
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
files = get_generated_images()
|
| 361 |
-
return [
|
| 362 |
-
(f["path"], f"{f['name']}\n{f['date']}")
|
| 363 |
-
for f in files
|
| 364 |
-
]
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
@spaces.GPU(duration=400)
|
| 368 |
-
def generate_all(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
|
| 369 |
-
progress=gr.Progress()):
|
| 370 |
-
outputs = [None] * (len(MODEL_CONFIGS) * 2)
|
| 371 |
-
for idx, model_name in enumerate(MODEL_CONFIGS.keys()):
|
| 372 |
-
try:
|
| 373 |
-
# Display progress for the specific model
|
| 374 |
-
# progress(0, desc=f"Starting generation for {model_name}...")
|
| 375 |
-
print(f"IMAGE GENERATING {model_name} ")
|
| 376 |
-
image, used_seed = generate_image(
|
| 377 |
-
model_name, prompt, negative_prompt, seed,
|
| 378 |
-
randomize_seed, width, height, guidance_scale,
|
| 379 |
-
num_inference_steps, progress
|
| 380 |
-
)
|
| 381 |
-
print(f"IMAGE GENERATIED {model_name} ")
|
| 382 |
-
# Update the respective model's tab with the generated image
|
| 383 |
-
# results[model_name].update(image)
|
| 384 |
-
# seeds[model_name].update(used_seed)
|
| 385 |
-
outputs[idx * 2] = image # Image slot
|
| 386 |
-
outputs[idx * 2 + 1] = seed # Seed slot
|
| 387 |
-
# outputs.extend([image, used_seed])
|
| 388 |
-
# Add intermediate results to progress * (len(all_outputs) - len(all_outputs))
|
| 389 |
-
print("YELID")
|
| 390 |
-
yield outputs + [None]
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
except Exception as e:
|
| 394 |
-
print(f"Error generating with {model_name}: {str(e)}")
|
| 395 |
-
outputs[idx * 2] = None
|
| 396 |
-
outputs[idx * 2 + 1] = None
|
| 397 |
-
|
| 398 |
-
# Update the gallery after generation
|
| 399 |
-
gallery_images = update_gallery()
|
| 400 |
-
# file_gallery.update(value=gallery_images)
|
| 401 |
-
return outputs
|
| 402 |
-
|
| 403 |
|
| 404 |
output_components = []
|
| 405 |
for model_name in MODEL_CONFIGS.keys():
|
|
@@ -420,12 +424,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 420 |
outputs=output_components,
|
| 421 |
)
|
| 422 |
|
| 423 |
-
refresh_button.click(
|
| 424 |
-
fn=update_gallery,
|
| 425 |
-
inputs=[],
|
| 426 |
-
outputs=[file_gallery],
|
| 427 |
-
)
|
| 428 |
-
|
| 429 |
demo.load(
|
| 430 |
fn=update_gallery,
|
| 431 |
inputs=[],
|
|
|
|
| 266 |
}
|
| 267 |
"""
|
| 268 |
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
@spaces.GPU(duration=400)
|
| 273 |
+
def generate_all(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
|
| 274 |
+
progress=gr.Progress()):
|
| 275 |
+
outputs = [None] * (len(MODEL_CONFIGS) * 2)
|
| 276 |
+
for idx, model_name in enumerate(MODEL_CONFIGS.keys()):
|
| 277 |
+
try:
|
| 278 |
+
# Display progress for the specific model
|
| 279 |
+
# progress(0, desc=f"Starting generation for {model_name}...")
|
| 280 |
+
print(f"IMAGE GENERATING {model_name} ")
|
| 281 |
+
image, used_seed = generate_image(
|
| 282 |
+
model_name, prompt, negative_prompt, seed,
|
| 283 |
+
randomize_seed, width, height, guidance_scale,
|
| 284 |
+
num_inference_steps, progress
|
| 285 |
+
)
|
| 286 |
+
print(f"IMAGE GENERATIED {model_name} ")
|
| 287 |
+
# Update the respective model's tab with the generated image
|
| 288 |
+
# results[model_name].update(image)
|
| 289 |
+
# seeds[model_name].update(used_seed)
|
| 290 |
+
outputs[idx * 2] = image # Image slot
|
| 291 |
+
outputs[idx * 2 + 1] = seed # Seed slot
|
| 292 |
+
# outputs.extend([image, used_seed])
|
| 293 |
+
# Add intermediate results to progress * (len(all_outputs) - len(all_outputs))
|
| 294 |
+
print("YELID")
|
| 295 |
+
yield outputs + [None]
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
except Exception as e:
|
| 299 |
+
print(f"Error generating with {model_name}: {str(e)}")
|
| 300 |
+
outputs[idx * 2] = None
|
| 301 |
+
outputs[idx * 2 + 1] = None
|
| 302 |
+
|
| 303 |
+
# Update the gallery after generation
|
| 304 |
+
gallery_images = update_gallery()
|
| 305 |
+
# file_gallery.update(value=gallery_images)
|
| 306 |
+
return outputs
|
| 307 |
+
|
| 308 |
+
def update_gallery():
|
| 309 |
+
"""Update the file gallery"""
|
| 310 |
+
files = get_generated_images()
|
| 311 |
+
return [
|
| 312 |
+
(f["path"], f"{f['name']}\n{f['date']}")
|
| 313 |
+
for f in files
|
| 314 |
+
]
|
| 315 |
+
|
| 316 |
with gr.Blocks(css=css) as demo:
|
| 317 |
with gr.Column(elem_id="col-container"):
|
| 318 |
gr.Markdown("# Multi-Model Image Generation")
|
|
|
|
| 399 |
)
|
| 400 |
refresh_button = gr.Button("Refresh Gallery",visible=True)
|
| 401 |
|
| 402 |
+
refresh_button.click(
|
| 403 |
+
fn=update_gallery,
|
| 404 |
+
inputs=[],
|
| 405 |
+
outputs=[file_gallery],
|
| 406 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
output_components = []
|
| 409 |
for model_name in MODEL_CONFIGS.keys():
|
|
|
|
| 424 |
outputs=output_components,
|
| 425 |
)
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
demo.load(
|
| 428 |
fn=update_gallery,
|
| 429 |
inputs=[],
|