Parthebhan commited on
Commit
6cd9e92
·
verified ·
1 Parent(s): 7c10767

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -1,33 +1,16 @@
1
  import gradio as gr
2
- from transformers import AutoModelForImageSegmentation, AutoTokenizer
3
  import torch
4
- from PIL import Image
5
 
6
- # Load the model
7
- model = AutoModelForImageSegmentation.from_pretrained("/absolute/path/to/gelan-c-seg.pt")
8
 
9
- # Load the tokenizer (if needed)
10
- tokenizer = AutoTokenizer.from_pretrained("path/to/tokenizer")
 
 
11
 
12
- # Define the prediction function
13
- def predict_segmentation(image):
14
- # Convert image to PyTorch tensor
15
- image = torch.tensor(image).permute(2, 0, 1).unsqueeze(0).float()
16
- # Perform inference
17
- output = model(image)
18
- # Process the output as needed (e.g., post-processing for segmentation masks)
19
-
20
- segmentation_mask = output.logits.argmax(dim=1).squeeze().detach().numpy()
21
- return segmentation_mask
22
 
23
- # Create a Gradio interface
24
- inputs = gr.inputs.Image(shape=(224, 224))
25
- outputs = gr.outputs.Image(type="numpy", label="Segmentation Mask")
26
- title = "Image Segmentation Demo"
27
- description = "Upload an image and get the segmentation mask."
28
- examples = [["example.jpg"]] # Add example images here if needed
29
- interface = gr.Interface(fn=predict_segmentation, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
30
-
31
- # Run the interface
32
- if __name__ == "__main__":
33
- interface.launch()
 
1
  import gradio as gr
 
2
  import torch
3
+ from ultralytics import YOLO
4
 
5
+ # Load YOLO model
6
+ model = YOLO("yolov9c-seg.pt")
7
 
8
+ # Define function to perform prediction
9
+ def predict_image(image):
10
+ result = model.predict(image, show=True, save=True)
11
+ return result
12
 
13
+ # Create Gradio interface
14
+ image_input = gr.inputs.Image()
15
+ gr.Interface(predict_image, image_input, "image").launch()
 
 
 
 
 
 
 
16