Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from gradio_client import Client, handle_file
|
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
5 |
import os
|
|
|
6 |
|
7 |
def upscale_image(url):
|
8 |
client = Client("doevent/Face-Real-ESRGAN")
|
@@ -13,21 +14,24 @@ def upscale_image(url):
|
|
13 |
)
|
14 |
# print("\nTask Completed!")
|
15 |
# return result
|
|
|
16 |
if os.path.exists(result):
|
17 |
with open(result, 'rb') as img_file:
|
18 |
img_data = img_file.read()
|
19 |
-
|
20 |
# Convert result to PNG
|
21 |
img = Image.open(BytesIO(img_data))
|
22 |
-
output = BytesIO()
|
23 |
-
img.save(output, format="PNG")
|
24 |
-
output.seek(0)
|
25 |
|
26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
27 |
os.remove(result)
|
28 |
-
|
29 |
print("\nTask Completed!")
|
30 |
-
return
|
31 |
|
32 |
|
33 |
app = gr.Interface(upscale_image,
|
|
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
5 |
import os
|
6 |
+
import tempfile
|
7 |
|
8 |
def upscale_image(url):
|
9 |
client = Client("doevent/Face-Real-ESRGAN")
|
|
|
14 |
)
|
15 |
# print("\nTask Completed!")
|
16 |
# return result
|
17 |
+
# Read the image from the file path returned by the model
|
18 |
if os.path.exists(result):
|
19 |
with open(result, 'rb') as img_file:
|
20 |
img_data = img_file.read()
|
21 |
+
|
22 |
# Convert result to PNG
|
23 |
img = Image.open(BytesIO(img_data))
|
|
|
|
|
|
|
24 |
|
25 |
+
# Save the converted image to a temporary file
|
26 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
|
27 |
+
img.save(temp_file, format="PNG")
|
28 |
+
temp_file_path = temp_file.name
|
29 |
+
|
30 |
+
# Optionally, delete the temp file after processing (you can remove this line if not needed)
|
31 |
os.remove(result)
|
32 |
+
|
33 |
print("\nTask Completed!")
|
34 |
+
return temp_file_path
|
35 |
|
36 |
|
37 |
app = gr.Interface(upscale_image,
|