Spaces:
Runtime error
Runtime error
Download app.py from PawelMar/LettuceSegmentAPI: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/spaces/PawelMar/LettuceSegmentAPI/resolve/main/app.py
- Command line
-
hf download hf://spaces/PawelMar/LettuceSegmentAPI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PawelMar/LettuceSegmentAPI/resolve/main/app.py
765 Bytes
| 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() | |