Spaces:
Sleeping
Sleeping
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 |
import requests
|
|
|
5 |
|
6 |
# Initialize the client
|
7 |
client = Client("not-lain/background-removal")
|
@@ -31,9 +32,15 @@ def process_file_via_api(f):
|
|
31 |
f=handle_file(f),
|
32 |
api_name="/png"
|
33 |
)
|
34 |
-
#
|
35 |
-
if result:
|
36 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
return None
|
38 |
|
39 |
# Example images
|
|
|
2 |
from gradio_client import Client, handle_file
|
3 |
from PIL import Image
|
4 |
import requests
|
5 |
+
import io
|
6 |
|
7 |
# Initialize the client
|
8 |
client = Client("not-lain/background-removal")
|
|
|
32 |
f=handle_file(f),
|
33 |
api_name="/png"
|
34 |
)
|
35 |
+
# Ensure the result is a valid file path
|
36 |
+
if isinstance(result, str):
|
37 |
return result
|
38 |
+
elif isinstance(result, bytes):
|
39 |
+
# If the result is bytes, convert to image and save to a file
|
40 |
+
image = Image.open(io.BytesIO(result))
|
41 |
+
output_path = "output.png"
|
42 |
+
image.save(output_path)
|
43 |
+
return output_path
|
44 |
return None
|
45 |
|
46 |
# Example images
|