Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,21 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Load the model for image segmentation
|
5 |
+
segmentation = pipeline("image-segmentation", model="nvidia/segformer-b0-finetuned-ade-512-512")
|
6 |
+
|
7 |
+
# Define a function to segment the input image
|
8 |
+
def segment_image(image):
|
9 |
+
result = segmentation(image)
|
10 |
+
# Return the segmentation mask
|
11 |
+
return result[0]['mask'] # Returns the mask as an image
|
12 |
+
|
13 |
+
# Create a Gradio interface
|
14 |
+
interface = gr.Interface(
|
15 |
+
fn=segment_image, # Function to be called for segmentation
|
16 |
+
inputs=gr.Image(type="pil"), # Input: image
|
17 |
+
outputs="image" # Output: segmented image (mask)
|
18 |
+
)
|
19 |
+
|
20 |
+
# Launch the Gradio app
|
21 |
+
interface.launch()
|