Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from gradio_client import Client, handle_file
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
|
|
|
| 5 |
|
| 6 |
def upscale_image(url):
|
| 7 |
client = Client("doevent/Face-Real-ESRGAN")
|
|
@@ -12,13 +13,21 @@ def upscale_image(url):
|
|
| 12 |
)
|
| 13 |
# print("\nTask Completed!")
|
| 14 |
# return result
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
output.seek(0)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
app = gr.Interface(upscale_image,
|
|
|
|
| 2 |
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 |
)
|
| 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 |
+
# Optionally, delete the temp file after processing
|
| 27 |
+
os.remove(result)
|
| 28 |
+
|
| 29 |
+
print("\nTask Completed!")
|
| 30 |
+
return output
|
| 31 |
|
| 32 |
|
| 33 |
app = gr.Interface(upscale_image,
|