Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import gradio as gr
|
|
4 |
from rembg import new_session
|
5 |
from cutter import remove, make_label
|
6 |
from utils import *
|
7 |
-
from PIL import Image
|
8 |
|
9 |
remove_bg_models = {
|
10 |
"U2NET": "u2net",
|
@@ -18,15 +17,15 @@ def predict(image):
|
|
18 |
session = new_session(remove_bg_models[default_model])
|
19 |
smoot = False
|
20 |
matting = (0, 0, 0) # Valores predeterminados para matting
|
21 |
-
bg_color =
|
22 |
try:
|
23 |
-
result = remove(session, image, smoot, matting, bg_color)
|
24 |
if isinstance(result, np.ndarray): # Verificar si la salida es un array de numpy
|
25 |
result = Image.fromarray(result.astype('uint8')) # Convertir el array de numpy a una imagen PIL
|
26 |
return result
|
27 |
except ValueError as err:
|
28 |
logging.error(err)
|
29 |
-
return None
|
30 |
|
31 |
with gr.Blocks(title="Remove background") as app:
|
32 |
gr.HTML("<center><h1>Background Remover</h1></center>")
|
@@ -35,7 +34,7 @@ with gr.Blocks(title="Remove background") as app:
|
|
35 |
input_img = gr.Image(type="pil", label="Input image")
|
36 |
with gr.Column():
|
37 |
output_img = gr.Image(type="pil", label="Result image")
|
38 |
-
|
39 |
with gr.Row(equal_height=True):
|
40 |
run_btn = gr.Button(value="Remove background", variant="primary")
|
41 |
clear_btn = gr.Button(value="Clear", variant="secondary")
|
|
|
4 |
from rembg import new_session
|
5 |
from cutter import remove, make_label
|
6 |
from utils import *
|
|
|
7 |
|
8 |
remove_bg_models = {
|
9 |
"U2NET": "u2net",
|
|
|
17 |
session = new_session(remove_bg_models[default_model])
|
18 |
smoot = False
|
19 |
matting = (0, 0, 0) # Valores predeterminados para matting
|
20 |
+
bg_color = False # Color de fondo predeterminado (no cambiar color)
|
21 |
try:
|
22 |
+
result, _ = remove(session, image, smoot, matting, bg_color)
|
23 |
if isinstance(result, np.ndarray): # Verificar si la salida es un array de numpy
|
24 |
result = Image.fromarray(result.astype('uint8')) # Convertir el array de numpy a una imagen PIL
|
25 |
return result
|
26 |
except ValueError as err:
|
27 |
logging.error(err)
|
28 |
+
return make_label(str(err)), None
|
29 |
|
30 |
with gr.Blocks(title="Remove background") as app:
|
31 |
gr.HTML("<center><h1>Background Remover</h1></center>")
|
|
|
34 |
input_img = gr.Image(type="pil", label="Input image")
|
35 |
with gr.Column():
|
36 |
output_img = gr.Image(type="pil", label="Result image")
|
37 |
+
|
38 |
with gr.Row(equal_height=True):
|
39 |
run_btn = gr.Button(value="Remove background", variant="primary")
|
40 |
clear_btn = gr.Button(value="Clear", variant="secondary")
|