Spaces:
Running
on
Zero
Running
on
Zero
RageshAntony
commited on
added gallery
Browse files- check_app.py +35 -3
check_app.py
CHANGED
@@ -167,8 +167,10 @@ def generate_image_with_progress(model_name,pipe, prompt, num_steps, guidance_sc
|
|
167 |
# Generate image
|
168 |
image = pipe(**common_args).images[0]
|
169 |
filepath = save_generated_image(image, model_name, prompt)
|
|
|
|
|
170 |
print(f"Saved image to: {filepath}")
|
171 |
-
return seed, image
|
172 |
|
173 |
@spaces.GPU(duration=170)
|
174 |
def create_pipeline_logic(prompt_text, model_name, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=4.5, num_inference_steps=40,):
|
@@ -251,7 +253,7 @@ def main():
|
|
251 |
step=1,
|
252 |
value=40,
|
253 |
)
|
254 |
-
|
255 |
for model_name, config in MODEL_CONFIGS.items():
|
256 |
with gr.Tab(model_name):
|
257 |
button = gr.Button(f"Run {model_name}")
|
@@ -264,7 +266,16 @@ def main():
|
|
264 |
width,
|
265 |
height,
|
266 |
guidance_scale,
|
267 |
-
num_inference_steps], outputs=[output, img])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
|
269 |
app.launch()
|
270 |
|
@@ -280,5 +291,26 @@ def save_generated_image(image, model_name, prompt):
|
|
280 |
image.save(filepath)
|
281 |
return filepath
|
282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
if __name__ == "__main__":
|
284 |
main()
|
|
|
167 |
# Generate image
|
168 |
image = pipe(**common_args).images[0]
|
169 |
filepath = save_generated_image(image, model_name, prompt)
|
170 |
+
# Then, reload the gallery
|
171 |
+
images, load_message = load_images_from_directory(directory_path)
|
172 |
print(f"Saved image to: {filepath}")
|
173 |
+
return seed, image, images
|
174 |
|
175 |
@spaces.GPU(duration=170)
|
176 |
def create_pipeline_logic(prompt_text, model_name, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=4.5, num_inference_steps=40,):
|
|
|
253 |
step=1,
|
254 |
value=40,
|
255 |
)
|
256 |
+
gallery : gr.Gallery = None
|
257 |
for model_name, config in MODEL_CONFIGS.items():
|
258 |
with gr.Tab(model_name):
|
259 |
button = gr.Button(f"Run {model_name}")
|
|
|
266 |
width,
|
267 |
height,
|
268 |
guidance_scale,
|
269 |
+
num_inference_steps], outputs=[output, img, gallery])
|
270 |
+
|
271 |
+
gallery = gr.Gallery(
|
272 |
+
label="Image Gallery",
|
273 |
+
show_label=True,
|
274 |
+
columns=4,
|
275 |
+
rows=3,
|
276 |
+
height=600,
|
277 |
+
object_fit="contain"
|
278 |
+
)
|
279 |
|
280 |
app.launch()
|
281 |
|
|
|
291 |
image.save(filepath)
|
292 |
return filepath
|
293 |
|
294 |
+
def load_images_from_directory(directory_path):
|
295 |
+
"""
|
296 |
+
Load all images from the specified directory.
|
297 |
+
Returns a list of image file paths.
|
298 |
+
"""
|
299 |
+
image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'}
|
300 |
+
directory = Path(directory_path)
|
301 |
+
|
302 |
+
if not directory.exists():
|
303 |
+
return [], f"Error: Directory '{directory_path}' does not exist"
|
304 |
+
|
305 |
+
image_files = [
|
306 |
+
str(f) for f in directory.iterdir()
|
307 |
+
if f.suffix.lower() in image_extensions and f.is_file()
|
308 |
+
]
|
309 |
+
|
310 |
+
if not image_files:
|
311 |
+
return [], f"No images found in directory '{directory_path}'"
|
312 |
+
|
313 |
+
return image_files, f"Found {len(image_files)} images"
|
314 |
+
|
315 |
if __name__ == "__main__":
|
316 |
main()
|