Spaces:
Running
on
Zero
Running
on
Zero
强制改为jpg格式
Browse files- __pycache__/config.cpython-310.pyc +0 -0
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +4 -5
- utils.py +8 -1
__pycache__/config.cpython-310.pyc
DELETED
|
Binary file (1.04 kB)
|
|
|
__pycache__/utils.cpython-310.pyc
DELETED
|
Binary file (3.78 kB)
|
|
|
app.py
CHANGED
|
@@ -177,12 +177,10 @@ def generate(
|
|
| 177 |
callback_on_step_end=callback2
|
| 178 |
).images
|
| 179 |
out_img = images[0]
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
out_img.save(img_io, format="PNG") # 使用 PNG 格式保存
|
| 183 |
-
img_io.seek(0)
|
| 184 |
progress(1, desc="Complete")
|
| 185 |
-
return
|
| 186 |
except GenerationError as e:
|
| 187 |
logger.warning(f"Generation validation error: {str(e)}")
|
| 188 |
raise gr.Error(str(e))
|
|
@@ -309,6 +307,7 @@ with gr.Blocks(css=custom_css).queue() as demo:
|
|
| 309 |
with gr.Column():
|
| 310 |
gr.Markdown("### Output")
|
| 311 |
result = gr.Image(
|
|
|
|
| 312 |
label="Generated Image",
|
| 313 |
elem_id="output-image"
|
| 314 |
)
|
|
|
|
| 177 |
callback_on_step_end=callback2
|
| 178 |
).images
|
| 179 |
out_img = images[0]
|
| 180 |
+
path = utils.save_image(out_img, "./outputs")
|
| 181 |
+
logger.info(f"output path: {path}")
|
|
|
|
|
|
|
| 182 |
progress(1, desc="Complete")
|
| 183 |
+
return path
|
| 184 |
except GenerationError as e:
|
| 185 |
logger.warning(f"Generation validation error: {str(e)}")
|
| 186 |
raise gr.Error(str(e))
|
|
|
|
| 307 |
with gr.Column():
|
| 308 |
gr.Markdown("### Output")
|
| 309 |
result = gr.Image(
|
| 310 |
+
type="filepath",
|
| 311 |
label="Generated Image",
|
| 312 |
elem_id="output-image"
|
| 313 |
)
|
utils.py
CHANGED
|
@@ -99,4 +99,11 @@ def free_memory() -> None:
|
|
| 99 |
if torch.cuda.is_available():
|
| 100 |
torch.cuda.empty_cache()
|
| 101 |
torch.cuda.ipc_collect()
|
| 102 |
-
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if torch.cuda.is_available():
|
| 100 |
torch.cuda.empty_cache()
|
| 101 |
torch.cuda.ipc_collect()
|
| 102 |
+
gc.collect()
|
| 103 |
+
|
| 104 |
+
def save_image(image, output_dir):
|
| 105 |
+
filename = str(uuid.uuid4()) + ".jpg"
|
| 106 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 107 |
+
filepath = os.path.join(output_dir, filename)
|
| 108 |
+
image.save(filepath, "JPEG", quality=80)
|
| 109 |
+
return filepath
|