Spaces:
Running
on
Zero
Running
on
Zero
RageshAntony
commited on
added Save
Browse files- check_app.py +16 -2
check_app.py
CHANGED
@@ -15,7 +15,9 @@ from diffusers import (
|
|
15 |
)
|
16 |
import gradio as gr
|
17 |
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
|
18 |
-
|
|
|
|
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
MAX_IMAGE_SIZE = 1024
|
21 |
|
@@ -163,7 +165,8 @@ def generate_image_with_progress(model_name,pipe, prompt, num_steps, guidance_sc
|
|
163 |
|
164 |
# Generate image
|
165 |
image = pipe(**common_args).images[0]
|
166 |
-
|
|
|
167 |
return seed, image
|
168 |
|
169 |
@spaces.GPU(duration=170)
|
@@ -264,6 +267,17 @@ def main():
|
|
264 |
|
265 |
app.launch()
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
if __name__ == "__main__":
|
269 |
main()
|
|
|
15 |
)
|
16 |
import gradio as gr
|
17 |
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
|
18 |
+
from pathlib import Path
|
19 |
+
import time
|
20 |
+
from datetime import datetime
|
21 |
MAX_SEED = np.iinfo(np.int32).max
|
22 |
MAX_IMAGE_SIZE = 1024
|
23 |
|
|
|
165 |
|
166 |
# Generate image
|
167 |
image = pipe(**common_args).images[0]
|
168 |
+
filepath = save_generated_image(image, model_name, prompt)
|
169 |
+
print(f"Saved image to: {filepath}")
|
170 |
return seed, image
|
171 |
|
172 |
@spaces.GPU(duration=170)
|
|
|
267 |
|
268 |
app.launch()
|
269 |
|
270 |
+
def save_generated_image(image, model_name, prompt):
|
271 |
+
"""Save generated image with timestamp and model name"""
|
272 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
273 |
+
# Create sanitized filename from prompt (first 30 chars)
|
274 |
+
prompt_part = "".join(c for c in prompt[:30] if c.isalnum() or c in (' ', '-', '_')).strip()
|
275 |
+
filename = f"{timestamp}_{model_name}_{prompt_part}.png"
|
276 |
+
path = Path(model_name)
|
277 |
+
path.mkdir(parents=True, exist_ok=True)
|
278 |
+
filepath = os.path.join(model_name, filename)
|
279 |
+
image.save(filepath)
|
280 |
+
return filepath
|
281 |
|
282 |
if __name__ == "__main__":
|
283 |
main()
|