Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
-
import torch
|
4 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def remove_background(input_image):
|
7 |
try:
|
8 |
-
# Initialize the
|
9 |
-
segmentor = pipeline(
|
10 |
-
|
11 |
-
|
12 |
-
device="cpu" # Use CPU for inference
|
13 |
-
)
|
14 |
|
15 |
# Process the image
|
16 |
result = segmentor(input_image)
|
|
|
17 |
return result['output_image']
|
18 |
except Exception as e:
|
19 |
raise gr.Error(f"Error processing image: {str(e)}")
|
@@ -55,7 +56,6 @@ with gr.Blocks(css=css) as demo:
|
|
55 |
|
56 |
with gr.Row():
|
57 |
with gr.Column():
|
58 |
-
# Correct implementation of input image
|
59 |
input_image = gr.Image(
|
60 |
label="Upload Image",
|
61 |
type="pil",
|
@@ -71,7 +71,6 @@ with gr.Blocks(css=css) as demo:
|
|
71 |
with gr.Row():
|
72 |
clear_btn = gr.Button("Clear")
|
73 |
process_btn = gr.Button("Remove Background", variant="primary")
|
74 |
-
download_btn = gr.Button("Download Result")
|
75 |
|
76 |
# Event handlers
|
77 |
process_btn.click(
|
@@ -85,17 +84,4 @@ with gr.Blocks(css=css) as demo:
|
|
85 |
outputs=[input_image, output_image]
|
86 |
)
|
87 |
|
88 |
-
# Example images
|
89 |
-
gr.Examples(
|
90 |
-
examples=[
|
91 |
-
["example1.jpg"],
|
92 |
-
["example2.jpg"],
|
93 |
-
["example3.jpg"]
|
94 |
-
],
|
95 |
-
inputs=input_image,
|
96 |
-
outputs=output_image,
|
97 |
-
fn=remove_background,
|
98 |
-
cache_examples=True
|
99 |
-
)
|
100 |
-
|
101 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
|
8 |
def remove_background(input_image):
|
9 |
try:
|
10 |
+
# Initialize the pipeline
|
11 |
+
segmentor = pipeline("image-segmentation",
|
12 |
+
model="briaai/RMBG-1.4",
|
13 |
+
device=-1) # CPU inference
|
|
|
|
|
14 |
|
15 |
# Process the image
|
16 |
result = segmentor(input_image)
|
17 |
+
|
18 |
return result['output_image']
|
19 |
except Exception as e:
|
20 |
raise gr.Error(f"Error processing image: {str(e)}")
|
|
|
56 |
|
57 |
with gr.Row():
|
58 |
with gr.Column():
|
|
|
59 |
input_image = gr.Image(
|
60 |
label="Upload Image",
|
61 |
type="pil",
|
|
|
71 |
with gr.Row():
|
72 |
clear_btn = gr.Button("Clear")
|
73 |
process_btn = gr.Button("Remove Background", variant="primary")
|
|
|
74 |
|
75 |
# Event handlers
|
76 |
process_btn.click(
|
|
|
84 |
outputs=[input_image, output_image]
|
85 |
)
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
demo.launch()
|