Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import traceback
|
|
|
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -16,7 +17,7 @@ def run_image_to_image(img: Image.Image, prompt: str, model: str) -> Image.Image
|
|
| 16 |
client = InferenceClient(token=token)
|
| 17 |
|
| 18 |
# Convert PIL image to bytes
|
| 19 |
-
with
|
| 20 |
img.save(tmp.name, format="PNG")
|
| 21 |
with open(tmp.name, "rb") as f:
|
| 22 |
input_bytes = f.read()
|
|
@@ -81,7 +82,7 @@ with gr.Blocks(title="图像编辑工具", css=".gradio-container {max-width: 98
|
|
| 81 |
def _run_and_pack(img: Image.Image, p: str, m: str):
|
| 82 |
result_img = run_image_to_image(img, p, m)
|
| 83 |
# 保存为临时文件以供下载
|
| 84 |
-
with
|
| 85 |
result_img.save(tmp.name)
|
| 86 |
return result_img, tmp.name
|
| 87 |
|
|
|
|
| 1 |
import os
|
| 2 |
import traceback
|
| 3 |
+
import tempfile
|
| 4 |
from typing import Optional
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 17 |
client = InferenceClient(token=token)
|
| 18 |
|
| 19 |
# Convert PIL image to bytes
|
| 20 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=True) as tmp:
|
| 21 |
img.save(tmp.name, format="PNG")
|
| 22 |
with open(tmp.name, "rb") as f:
|
| 23 |
input_bytes = f.read()
|
|
|
|
| 82 |
def _run_and_pack(img: Image.Image, p: str, m: str):
|
| 83 |
result_img = run_image_to_image(img, p, m)
|
| 84 |
# 保存为临时文件以供下载
|
| 85 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
| 86 |
result_img.save(tmp.name)
|
| 87 |
return result_img, tmp.name
|
| 88 |
|