Spaces:
Runtime error
Runtime error
| 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() | |