Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from diffusers import DDIMScheduler, EulerAncestralDiscreteScheduler
|
|
8 |
import cv2
|
9 |
import torch
|
10 |
import os
|
|
|
11 |
|
12 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
13 |
|
@@ -40,11 +41,16 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
40 |
generator=generator
|
41 |
).images[0]
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
output_image.save(
|
46 |
|
47 |
-
return
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
css = """
|
50 |
#col-container {
|
@@ -130,6 +136,10 @@ with gr.Blocks(css=css) as demo:
|
|
130 |
fn=infer,
|
131 |
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
132 |
outputs=[result]
|
|
|
|
|
|
|
|
|
133 |
)
|
134 |
|
135 |
demo.queue().launch()
|
|
|
8 |
import cv2
|
9 |
import torch
|
10 |
import os
|
11 |
+
import uuid # UUIDを使用するために追加
|
12 |
|
13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
|
|
|
41 |
generator=generator
|
42 |
).images[0]
|
43 |
|
44 |
+
# UUIDを使用して一意のファイル名を生成
|
45 |
+
unique_filename = f"output_image_{uuid.uuid4().hex}.png"
|
46 |
+
output_image.save(unique_filename, format="PNG")
|
47 |
|
48 |
+
return unique_filename # ファイルパスを返す
|
49 |
+
|
50 |
+
def cleanup(filename):
|
51 |
+
if os.path.exists(filename):
|
52 |
+
os.remove(filename)
|
53 |
+
print(f"Deleted temporary file: {filename}")
|
54 |
|
55 |
css = """
|
56 |
#col-container {
|
|
|
136 |
fn=infer,
|
137 |
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
138 |
outputs=[result]
|
139 |
+
).then(
|
140 |
+
fn=cleanup,
|
141 |
+
inputs=[result],
|
142 |
+
outputs=[]
|
143 |
)
|
144 |
|
145 |
demo.queue().launch()
|