Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
from gradio_client import Client, handle_file
|
| 3 |
from gradio_imageslider import ImageSlider
|
| 4 |
from PIL import Image
|
| 5 |
-
import requests
|
| 6 |
import tempfile
|
| 7 |
import os
|
| 8 |
|
|
@@ -10,10 +9,19 @@ import os
|
|
| 10 |
client = Client("not-lain/background-removal")
|
| 11 |
|
| 12 |
def process_image_via_api(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
result = client.predict(
|
| 14 |
-
image=handle_file(
|
| 15 |
api_name="/image"
|
| 16 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Convert the output tuple to PIL images and return
|
| 18 |
if result:
|
| 19 |
processed_image_path = result[0]
|
|
@@ -94,4 +102,4 @@ demo = gr.TabbedInterface(
|
|
| 94 |
)
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
-
demo.launch(show_error=True)
|
|
|
|
| 2 |
from gradio_client import Client, handle_file
|
| 3 |
from gradio_imageslider import ImageSlider
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
|
|
|
|
| 9 |
client = Client("not-lain/background-removal")
|
| 10 |
|
| 11 |
def process_image_via_api(image):
|
| 12 |
+
# Сохраняем изображение во временный файл
|
| 13 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
| 14 |
+
image.save(temp_file.name)
|
| 15 |
+
temp_file_path = temp_file.name
|
| 16 |
+
|
| 17 |
result = client.predict(
|
| 18 |
+
image=handle_file(temp_file_path),
|
| 19 |
api_name="/image"
|
| 20 |
)
|
| 21 |
+
|
| 22 |
+
# Удаляем временный файл после использования
|
| 23 |
+
os.remove(temp_file_path)
|
| 24 |
+
|
| 25 |
# Convert the output tuple to PIL images and return
|
| 26 |
if result:
|
| 27 |
processed_image_path = result[0]
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
+
demo.launch(show_error=True)
|