Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForImageSegmentation, AutoTokenizer
|
3 |
import torch
|
4 |
-
from
|
5 |
|
6 |
-
# Load
|
7 |
-
model =
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|