Spaces:
Runtime error
Runtime error
Download app.py from amtechinscribe/AMVision: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/spaces/amtechinscribe/AMVision/resolve/main/app.py
- Command line
-
hf download hf://spaces/amtechinscribe/AMVision/app.py
-
curl -L -o app.py https://huggingface.co/spaces/amtechinscribe/AMVision/resolve/main/app.py
815 Bytes
| from ultralytics import YOLO | |
| from PIL import Image | |
| import numpy as np | |
| import gradio as gr | |
| # Load a YOLOv8 model (YOLOv8n is the smallest and fastest version) | |
| model = YOLO('yolov8n.pt') | |
| def detect_objects(image): | |
| results = model(image) | |
| rendered_image = results[0].plot() # This returns a numpy array with the bounding boxes drawn | |
| return Image.fromarray(rendered_image) # Convert the numpy array back to an image | |
| # Define the Gradio interface | |
| interface = gr.Interface( | |
| fn=detect_objects, # Function to process the input | |
| inputs=gr.Image(type="pil"), # Input is an image | |
| outputs=gr.Image(type="pil"), # Output is an image | |
| title="YOLOv8 Object Detection", | |
| description="Upload an image to detect objects using YOLOv8." | |
| ) | |
| # Launch the Gradio interface | |
| interface.launch(share=True) | |