Spaces:
Runtime error
Runtime error
Maruf
commited on
Commit
·
f863e99
1
Parent(s):
61008a8
Add application file
Browse files- app.py +21 -0
- readme.md +13 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import json
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load YOLOv5s pretrained on COCO
|
| 6 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
|
| 7 |
+
|
| 8 |
+
def detect(image):
|
| 9 |
+
results = model(image)
|
| 10 |
+
df = results.pandas().xyxy[0] # xmin, ymin, xmax, ymax, confidence, class, name
|
| 11 |
+
return json.loads(df.to_json(orient="records"))
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=detect,
|
| 15 |
+
inputs=gr.Image(type="pil"),
|
| 16 |
+
outputs="json",
|
| 17 |
+
title="COCO Object Detection (YOLOv5)",
|
| 18 |
+
description="Upload an image to detect objects (COCO classes). Output is JSON."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
iface.launch()
|
readme.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# COCO Object Detection API (Free on Hugging Face Spaces)
|
| 2 |
+
|
| 3 |
+
Deploys a YOLOv5s model pretrained on MS COCO.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
- Upload image via web UI or API
|
| 7 |
+
- Returns JSON (bounding boxes, class, confidence)
|
| 8 |
+
|
| 9 |
+
## Example API Call
|
| 10 |
+
```bash
|
| 11 |
+
curl -X POST \
|
| 12 |
+
-F "data=@your_image.jpg" \
|
| 13 |
+
https://YOUR_SPACE_URL/run/predict
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
pillow
|
| 4 |
+
gradio
|