File size: 765 Bytes
d2ea47e
612b741
4e5bd89
b163a45
d2ea47e
dafdb47
612b741
 
 
c10751c
9783e18
 
c10751c
 
bf2077b
612b741
 
 
 
9907a02
4e5bd89
612b741
 
 
d2ea47e
b163a45
612b741
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from ultralytics import YOLO
import json


def yoloV8_func(image: gr.Image = None):
    model_path = "models/last.pt"
    model = YOLO(model_path)
    results = model.predict(image)
    masks_json = []
    for result in results:
        if result.masks:
            masks_json.append([{"x": format(point[0], '.2f'), "y": format(point[1], '.2f')} for point in result.masks.xy[0]])
    masks_json = json.dumps(masks_json)
    return masks_json


yolo_app = gr.Interface(
    fn=yoloV8_func,
    inputs=gr.Image(type="filepath", label="Input Image"),
    outputs="json",
    title="YOLOv8: Custom Instance segmentation on lettuce leafs",
    cache_examples=True,
)

# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
yolo_app.launch()