Flux-api / app.py
Doubleupai's picture
Create app.py
e151d05 verified
raw
history blame
1.05 kB
import gradio as gr
from rembg import remove
from PIL import Image
import io
def remove_background(input_image):
# Преобразуем изображение в байты
img_byte_arr = io.BytesIO()
input_image.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
# Удаляем фон с помощью модели RemBgV0
output_image = remove(img_byte_arr)
# Преобразуем результат обратно в изображение
output_image = Image.open(io.BytesIO(output_image))
return output_image
# Создаем Gradio интерфейс
iface = gr.Interface(
fn=remove_background,
inputs=gr.Image(type="pil", label="Входное изображение"),
outputs=gr.Image(type="pil", label="Изображение без фона"),
title="Удаление фона с помощью RemBgV0",
description="Загрузите изображение, чтобы удалить фон."
)
# Запускаем интерфейс
iface.launch()