Download app.py from Armyman91/AOL_AI: direct link, hf CLI and curl.
- Browser
- Download file 932 Bytes
-
https://huggingface.co/Armyman91/AOL_AI/resolve/main/app.py
- Command line
-
hf download hf://Armyman91/AOL_AI/app.py
-
curl -L -o app.py https://huggingface.co/Armyman91/AOL_AI/resolve/main/app.py
932 Bytes
| import gradio as gr | |
| from ultralytics import YOLO | |
| # Load YOLO model | |
| model = YOLO('yolov8n.pt') | |
| def detect_and_count_cars(image): | |
| results = model.predict(image, conf=0.25) | |
| detections = results[0].boxes.boxes.cpu().numpy() | |
| car_count = 0 | |
| # Count cars | |
| for detection in detections: | |
| class_id = int(detection[5]) | |
| if model.names[class_id] == 'car': | |
| car_count += 1 | |
| annotated_image = results[0].plot() | |
| return annotated_image, f"Number of cars detected: {car_count}" | |
| # Create Gradio interface | |
| interface = gr.Interface( | |
| fn=detect_and_count_cars, | |
| inputs=gr.Image(type="numpy", label="Upload an Image"), | |
| outputs=[ | |
| gr.Image(type="numpy", label="Annotated Image"), | |
| gr.Textbox(label="Car Count") | |
| ], | |
| title="Car Detection and Counting", | |
| description="Upload an image to detect and count cars using YOLOv8." | |
| ) | |
| # Launch the interface | |
| interface.launch() | |