jigara56 commited on
Commit
abc372e
·
verified ·
1 Parent(s): a6909b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -1,3 +1,21 @@
 
1
  import gradio as gr
2
 
3
- gr.Interface.load("models/nvidia/segformer-b0-finetuned-ade-512-512").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()