# Smart Statue Detector API - Documentation ## Overview REST API built with **FastAPI** + **YOLOv8** for detecting **persons** and **Egyptian statues** in images. - 🟢 **Green box** → Person - 🔴 **Red box** → Statue (with real name) **Base URL:** ``` https://morefaat69-smart-statue-detector.hf.space ``` --- ## Endpoints ### `GET /` Health check - تأكد إن الـ API شغال. **Response:** ```json { "message": "AI API is running " } ``` --- ### `POST /predict-image` Upload an image → get detections + annotated output image. #### Request | Field | Type | Description | |-------|------|-------------| | `file` | `multipart/form-data` | Image file (jpg, jpeg, png) | #### Response | Field | Type | Description | |-------|------|-------------| | `total_count` | `int` | Total detections (persons + statues) | | `persons` | `int` | Number of persons detected | | `statues` | `int` | Number of statues detected | | `output_image_url` | `string` | URL of annotated image (temporary) | | `output_image_base64` | `string` | Base64 encoded annotated image | | `detections` | `array` | List of all detections | #### Detection Object | Field | Type | Description | |-------|------|-------------| | `type` | `string` | `"person"` or `"statue"` | | `name` | `string` | `"Person"` or statue name (e.g. `"Hathor Capital"`) | | `confidence` | `float` | Confidence score (0.0 → 1.0) | | `bbox` | `array` | Bounding box `[x1, y1, x2, y2]` | #### Example Response ```json { "total_count": 2, "persons": 1, "statues": 1, "output_image_url": "https://morefaat69-smart-statue-detector.hf.space/uploads/output_test.jpeg", "output_image_base64": "data:image/jpeg;base64,/9j/4AAQSkZJRgAB...", "detections": [ { "type": "person", "name": "Person", "confidence": 0.9128, "bbox": [56, 399, 577, 892] }, { "type": "statue", "name": "Hathor Capital", "confidence": 0.3147, "bbox": [329, 0, 683, 721] } ] } ``` --- ## How to Connect (Integration Examples) ### cURL ```bash curl -X POST "https://morefaat69-smart-statue-detector.hf.space/predict-image" \ -H "accept: application/json" \ -F "file=@your_image.jpg;type=image/jpeg" ``` --- ### Python ```python import requests import base64 from PIL import Image from io import BytesIO url = "https://morefaat69-smart-statue-detector.hf.space/predict-image" with open("your_image.jpg", "rb") as f: response = requests.post(url, files={"file": f}) data = response.json() print(f"Persons: {data['persons']}") print(f"Statues: {data['statues']}") for d in data["detections"]: print(f"{d['type']} → {d['name']} ({d['confidence']:.2%})") # عرض الصورة الناتجة img_data = base64.b64decode(data["output_image_base64"].split(",")[1]) img = Image.open(BytesIO(img_data)) img.show() ``` --- ### JavaScript / React ```javascript const detectObjects = async (imageFile) => { const formData = new FormData(); formData.append("file", imageFile); const response = await fetch( "https://morefaat69-smart-statue-detector.hf.space/predict-image", { method: "POST", body: formData, } ); const data = await response.json(); console.log(`Persons: ${data.persons}`); console.log(`Statues: ${data.statues}`); // عرض الصورة الناتجة مباشرة return (
{d.type === "statue" ? "🏛️" : "👤"} {d.name} — {(d.confidence * 100).toFixed(1)}%
))}