ovi054 commited on
Commit
68c2b09
·
verified ·
1 Parent(s): 5599066

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
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
- img = Image.open(BytesIO(result))
16
- output = BytesIO()
17
- img.save(output, format="PNG")
18
- output.seek(0)
19
 
20
- print("\nTask Completed!")
21
- return output
 
 
 
 
 
 
 
 
 
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,