Spaces:
Sleeping
Sleeping
add gallery for iterations
Browse files
app.py
CHANGED
@@ -2,6 +2,24 @@ import gradio as gr
|
|
2 |
from main import main
|
3 |
from arguments import parse_args
|
4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def generate_image(prompt, model, num_iterations, learning_rate, progress=gr.Progress(track_tqdm=True)):
|
7 |
# Set up arguments
|
@@ -40,12 +58,13 @@ def generate_image(prompt, model, num_iterations, learning_rate, progress=gr.Pro
|
|
40 |
image_path = f"{save_dir}/best_image.png"
|
41 |
|
42 |
if os.path.exists(image_path):
|
43 |
-
|
|
|
44 |
else:
|
45 |
-
return None, "Image generation completed, but the file was not found."
|
46 |
|
47 |
except Exception as e:
|
48 |
-
return None, f"An error occurred: {str(e)}"
|
49 |
|
50 |
# Create Gradio interface
|
51 |
title="# ReNO: Enhancing One-step Text-to-Image Models through Reward-based Noise Optimization"
|
@@ -92,11 +111,12 @@ with gr.Blocks() as demo:
|
|
92 |
with gr.Column():
|
93 |
output_image = gr.Image(type="filepath", label="Generated Image")
|
94 |
status = gr.Textbox(label="Status")
|
|
|
95 |
|
96 |
submit_btn.click(
|
97 |
fn = generate_image,
|
98 |
inputs = [prompt, chosen_model, n_iter, learning_rate],
|
99 |
-
outputs = [output_image, status]
|
100 |
)
|
101 |
|
102 |
# Launch the app
|
|
|
2 |
from main import main
|
3 |
from arguments import parse_args
|
4 |
import os
|
5 |
+
import glob
|
6 |
+
|
7 |
+
def list_iter_images(save_dir):
|
8 |
+
# Specify the image extensions you want to search for
|
9 |
+
image_extensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp'] # Add more if needed
|
10 |
+
|
11 |
+
# Create a list to store the image file paths
|
12 |
+
image_paths = []
|
13 |
+
|
14 |
+
# Iterate through the specified image extensions and get the file paths
|
15 |
+
for ext in image_extensions:
|
16 |
+
# Use glob to find all image files with the given extension
|
17 |
+
image_paths.extend(glob.glob(os.path.join(save_dir, f'*.{ext}')))
|
18 |
+
|
19 |
+
# Now image_paths contains the list of all image file paths
|
20 |
+
print(image_paths)
|
21 |
+
|
22 |
+
return image_paths
|
23 |
|
24 |
def generate_image(prompt, model, num_iterations, learning_rate, progress=gr.Progress(track_tqdm=True)):
|
25 |
# Set up arguments
|
|
|
58 |
image_path = f"{save_dir}/best_image.png"
|
59 |
|
60 |
if os.path.exists(image_path):
|
61 |
+
iter_images = list_iter_images(save_dir)
|
62 |
+
return image_path, f"Image generated successfully and saved at {image_path}", iter_images
|
63 |
else:
|
64 |
+
return None, "Image generation completed, but the file was not found.", None
|
65 |
|
66 |
except Exception as e:
|
67 |
+
return None, f"An error occurred: {str(e)}", None
|
68 |
|
69 |
# Create Gradio interface
|
70 |
title="# ReNO: Enhancing One-step Text-to-Image Models through Reward-based Noise Optimization"
|
|
|
111 |
with gr.Column():
|
112 |
output_image = gr.Image(type="filepath", label="Generated Image")
|
113 |
status = gr.Textbox(label="Status")
|
114 |
+
iter_gallery = gr.Gallery(label="Iterations")
|
115 |
|
116 |
submit_btn.click(
|
117 |
fn = generate_image,
|
118 |
inputs = [prompt, chosen_model, n_iter, learning_rate],
|
119 |
+
outputs = [output_image, status, iter_gallery]
|
120 |
)
|
121 |
|
122 |
# Launch the app
|