Doubleupai commited on
Commit
e151d05
·
verified ·
1 Parent(s): 32257c9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rembg import remove
3
+ from PIL import Image
4
+ import io
5
+
6
+ def remove_background(input_image):
7
+ # Преобразуем изображение в байты
8
+ img_byte_arr = io.BytesIO()
9
+ input_image.save(img_byte_arr, format='PNG')
10
+ img_byte_arr = img_byte_arr.getvalue()
11
+
12
+ # Удаляем фон с помощью модели RemBgV0
13
+ output_image = remove(img_byte_arr)
14
+
15
+ # Преобразуем результат обратно в изображение
16
+ output_image = Image.open(io.BytesIO(output_image))
17
+ return output_image
18
+
19
+ # Создаем Gradio интерфейс
20
+ iface = gr.Interface(
21
+ fn=remove_background,
22
+ inputs=gr.Image(type="pil", label="Входное изображение"),
23
+ outputs=gr.Image(type="pil", label="Изображение без фона"),
24
+ title="Удаление фона с помощью RemBgV0",
25
+ description="Загрузите изображение, чтобы удалить фон."
26
+ )
27
+
28
+ # Запускаем интерфейс
29
+ iface.launch()