Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from PIL import Image
|
|
| 11 |
import os
|
| 12 |
import random
|
| 13 |
import gc
|
|
|
|
| 14 |
|
| 15 |
def clear_memory():
|
| 16 |
gc.collect()
|
|
@@ -311,6 +312,16 @@ def process_image_batch(images, pipe, prompt, negative_prompt, num_inference_ste
|
|
| 311 |
clear_memory() # Clear memory after each batch
|
| 312 |
return all_processed_images
|
| 313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
# Define the function to generate images
|
| 315 |
def generate_images_with_progress(prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, control_images, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 316 |
global controlnet_pipe, pipe, reference_pipe
|
|
@@ -378,17 +389,10 @@ def generate_images_with_progress(prompt, negative_prompt, batch_count, use_cont
|
|
| 378 |
|
| 379 |
clear_memory()
|
| 380 |
|
| 381 |
-
#
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
# Save images as PNG files for download
|
| 385 |
-
output_files = []
|
| 386 |
-
for i, img in enumerate(pil_images):
|
| 387 |
-
output_path = f"output_{i}.png"
|
| 388 |
-
img.save(output_path, format="PNG")
|
| 389 |
-
output_files.append(output_path)
|
| 390 |
|
| 391 |
-
return
|
| 392 |
|
| 393 |
# Function to extract PNG metadata
|
| 394 |
def extract_png_info(image_path):
|
|
@@ -469,8 +473,7 @@ with gr.Blocks() as demo:
|
|
| 469 |
allow_preview=False
|
| 470 |
)
|
| 471 |
generate_button = gr.Button("Generate Images")
|
| 472 |
-
gallery = gr.Gallery(label="Generated Images", show_label=False, elem_id="gallery", height=
|
| 473 |
-
download_links = gr.Files(label="Download Generated Images")
|
| 474 |
|
| 475 |
selected_style = gr.State(value="Anime Studio Dance")
|
| 476 |
|
|
@@ -524,13 +527,12 @@ with gr.Blocks() as demo:
|
|
| 524 |
selected_images = [img[1] for img in selected_folder_images]
|
| 525 |
# Adjust the batch_count here to generate the desired number of images
|
| 526 |
selected_images = selected_images * batch_count
|
| 527 |
-
|
| 528 |
-
return pil_images, output_files
|
| 529 |
|
| 530 |
generate_button.click(
|
| 531 |
generate_images_with_folder_images,
|
| 532 |
inputs=[prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, use_control_folder, selected_folder_images, batch_images_input, num_inference_steps, control_image],
|
| 533 |
-
outputs=
|
| 534 |
)
|
| 535 |
|
| 536 |
metadata_button = gr.Button("Extract Metadata")
|
|
|
|
| 11 |
import os
|
| 12 |
import random
|
| 13 |
import gc
|
| 14 |
+
import tempfile
|
| 15 |
|
| 16 |
def clear_memory():
|
| 17 |
gc.collect()
|
|
|
|
| 312 |
clear_memory() # Clear memory after each batch
|
| 313 |
return all_processed_images
|
| 314 |
|
| 315 |
+
# Function to save images as PNG and return their paths
|
| 316 |
+
def save_images_as_png(images):
|
| 317 |
+
temp_dir = tempfile.mkdtemp()
|
| 318 |
+
png_paths = []
|
| 319 |
+
for i, img in enumerate(images):
|
| 320 |
+
png_path = os.path.join(temp_dir, f"image_{i}.png")
|
| 321 |
+
img.save(png_path, "PNG")
|
| 322 |
+
png_paths.append(png_path)
|
| 323 |
+
return png_paths
|
| 324 |
+
|
| 325 |
# Define the function to generate images
|
| 326 |
def generate_images_with_progress(prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, control_images, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
| 327 |
global controlnet_pipe, pipe, reference_pipe
|
|
|
|
| 389 |
|
| 390 |
clear_memory()
|
| 391 |
|
| 392 |
+
# Save images as PNG and return their paths
|
| 393 |
+
png_paths = save_images_as_png(images)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
+
return png_paths
|
| 396 |
|
| 397 |
# Function to extract PNG metadata
|
| 398 |
def extract_png_info(image_path):
|
|
|
|
| 473 |
allow_preview=False
|
| 474 |
)
|
| 475 |
generate_button = gr.Button("Generate Images")
|
| 476 |
+
gallery = gr.Gallery(label="Generated Images", show_label=False, elem_id="gallery", height=820)
|
|
|
|
| 477 |
|
| 478 |
selected_style = gr.State(value="Anime Studio Dance")
|
| 479 |
|
|
|
|
| 527 |
selected_images = [img[1] for img in selected_folder_images]
|
| 528 |
# Adjust the batch_count here to generate the desired number of images
|
| 529 |
selected_images = selected_images * batch_count
|
| 530 |
+
return generate_images_with_progress(prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, selected_images, num_inference_steps, progress)
|
|
|
|
| 531 |
|
| 532 |
generate_button.click(
|
| 533 |
generate_images_with_folder_images,
|
| 534 |
inputs=[prompt, negative_prompt, batch_count, use_controlnet, controlnet_type, mode, use_control_folder, selected_folder_images, batch_images_input, num_inference_steps, control_image],
|
| 535 |
+
outputs=gallery
|
| 536 |
)
|
| 537 |
|
| 538 |
metadata_button = gr.Button("Extract Metadata")
|