Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -23,13 +23,12 @@ from diffusers import (
|
|
23 |
UniPCMultistepScheduler,
|
24 |
)
|
25 |
|
26 |
-
# 一時ファイルの管理設定
|
27 |
TEMP_DIR = "temp_images"
|
28 |
-
FILE_RETENTION_PERIOD = 3600
|
29 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
30 |
|
31 |
def cleanup_old_files():
|
32 |
-
"""
|
33 |
current_time = time.time()
|
34 |
pattern = os.path.join(TEMP_DIR, "output_*.png")
|
35 |
|
@@ -55,11 +54,9 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
55 |
MAX_IMAGE_SIZE = 1216
|
56 |
|
57 |
@spaces.GPU
|
58 |
-
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, sampler_name)
|
59 |
-
# 古い一時ファイルの削除
|
60 |
cleanup_old_files()
|
61 |
|
62 |
-
# サンプラーの設定
|
63 |
if sampler_name == "DDIM":
|
64 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
65 |
elif sampler_name == "DPMSolverMultistep":
|
@@ -96,11 +93,9 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
96 |
generator=generator
|
97 |
).images[0]
|
98 |
|
99 |
-
# RGBモードで保存
|
100 |
if output_image.mode != 'RGB':
|
101 |
output_image = output_image.convert('RGB')
|
102 |
|
103 |
-
# 一時ファイルとして保存
|
104 |
timestamp = int(time.time())
|
105 |
temp_filename = os.path.join(TEMP_DIR, f"output_{timestamp}.png")
|
106 |
output_image.save(temp_filename)
|
@@ -117,9 +112,7 @@ css = """
|
|
117 |
with gr.Blocks(css=css) as demo:
|
118 |
with gr.Column(elem_id="col-container"):
|
119 |
gr.Markdown("""
|
120 |
-
|
121 |
-
using [illustrious_pencil-XL](https://huggingface.co/bluepen5805/illustrious_pencil-XL)
|
122 |
-
""")
|
123 |
|
124 |
with gr.Row():
|
125 |
prompt = gr.Text(
|
@@ -134,7 +127,7 @@ with gr.Blocks(css=css) as demo:
|
|
134 |
result = gr.Image(
|
135 |
label="Result",
|
136 |
show_label=False,
|
137 |
-
type="filepath",
|
138 |
elem_id="output_image"
|
139 |
)
|
140 |
|
@@ -202,7 +195,6 @@ with gr.Blocks(css=css) as demo:
|
|
202 |
outputs=[result]
|
203 |
)
|
204 |
|
205 |
-
# 起動時に古いファイルを削除
|
206 |
cleanup_old_files()
|
207 |
|
208 |
demo.queue().launch()
|
|
|
23 |
UniPCMultistepScheduler,
|
24 |
)
|
25 |
|
|
|
26 |
TEMP_DIR = "temp_images"
|
27 |
+
FILE_RETENTION_PERIOD = 3600
|
28 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
29 |
|
30 |
def cleanup_old_files():
|
31 |
+
"""Delete old temporary files"""
|
32 |
current_time = time.time()
|
33 |
pattern = os.path.join(TEMP_DIR, "output_*.png")
|
34 |
|
|
|
54 |
MAX_IMAGE_SIZE = 1216
|
55 |
|
56 |
@spaces.GPU
|
57 |
+
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, sampler_name)
|
|
|
58 |
cleanup_old_files()
|
59 |
|
|
|
60 |
if sampler_name == "DDIM":
|
61 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
62 |
elif sampler_name == "DPMSolverMultistep":
|
|
|
93 |
generator=generator
|
94 |
).images[0]
|
95 |
|
|
|
96 |
if output_image.mode != 'RGB':
|
97 |
output_image = output_image.convert('RGB')
|
98 |
|
|
|
99 |
timestamp = int(time.time())
|
100 |
temp_filename = os.path.join(TEMP_DIR, f"output_{timestamp}.png")
|
101 |
output_image.save(temp_filename)
|
|
|
112 |
with gr.Blocks(css=css) as demo:
|
113 |
with gr.Column(elem_id="col-container"):
|
114 |
gr.Markdown("""
|
115 |
+
T2I FurryStyle BetaVer""")
|
|
|
|
|
116 |
|
117 |
with gr.Row():
|
118 |
prompt = gr.Text(
|
|
|
127 |
result = gr.Image(
|
128 |
label="Result",
|
129 |
show_label=False,
|
130 |
+
type="filepath",
|
131 |
elem_id="output_image"
|
132 |
)
|
133 |
|
|
|
195 |
outputs=[result]
|
196 |
)
|
197 |
|
|
|
198 |
cleanup_old_files()
|
199 |
|
200 |
demo.queue().launch()
|