Spaces:
Runtime error
Runtime error
Update app.py
#2
by
jigara56
- opened
app.py
CHANGED
@@ -1,3 +1,20 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Load the image segmentation model using the pipeline
|
5 |
+
segmentation = pipeline("image-segmentation", model="nvidia/segformer-b0-finetuned-ade-512-512")
|
6 |
+
|
7 |
+
# Function to process the image and return the segmentation mask
|
8 |
+
def segment_image(image):
|
9 |
+
result = segmentation(image)
|
10 |
+
return result[0]['mask'] # The segmentation mask is returned as an image
|
11 |
+
|
12 |
+
# Create the Gradio interface
|
13 |
+
interface = gr.Interface(
|
14 |
+
fn=segment_image, # The function to call for segmentation
|
15 |
+
inputs=gr.Image(type="pil"), # Accepts image as input
|
16 |
+
outputs="image" # Outputs the segmentation mask
|
17 |
+
)
|
18 |
+
|
19 |
+
# Launch the interface
|
20 |
+
interface.launch()
|