File size: 2,058 Bytes
8a7ddf0
9cf599c
 
 
 
8a7ddf0
 
9cf599c
8a7ddf0
 
9cf599c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: Anomaly Detection API
emoji: πŸ”
colorFrom: blue
colorTo: red
sdk: docker
pinned: false
license: mit
---

# πŸ” Anomaly Detection API

Real-time anomaly detection for electrical components using PatchCore + OpenCV classification.

## πŸš€ Quick Start

### API Endpoint

**POST** `/infer`

**Request:**
```json
{
  "image_url": "https://example.com/your-image.jpg"
}
```

**Response:**
```json
{
  "label": "Normal",
  "boxed_url": "https://cloudinary.com/boxed_image.jpg",
  "mask_url": "https://cloudinary.com/anomaly_mask.png",
  "filtered_url": "https://cloudinary.com/filtered_anomalies.png",
  "boxes": []
}
```

### Example Usage

```bash
curl -X POST "https://YOUR_USERNAME-anomaly-detection-api.hf.space/infer" \
  -H "Content-Type: application/json" \
  -d '{"image_url": "https://example.com/test.jpg"}'
```

```python
import requests

response = requests.post(
    "https://YOUR_USERNAME-anomaly-detection-api.hf.space/infer",
    json={"image_url": "https://example.com/test.jpg"}
)

result = response.json()
print(f"Classification: {result['label']}")
print(f"Boxed Image: {result['boxed_url']}")
```

## πŸ“‹ Classification Labels

- **Normal** - No anomalies detected
- **Full Wire Overload** - Entire wire showing overload
- **Point Overload (Faulty)** - Localized overload points

## πŸ”§ Technical Details

- **Model:** PatchCore (anomaly detection)
- **Classification:** OpenCV-based heuristics
- **Response Time:** ~5 seconds
- **Max Image Size:** Unlimited (auto-resized)

## 🌐 Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/` | GET | API documentation |
| `/health` | GET | Health check |
| `/infer` | POST | Run inference |

## πŸ“¦ Output Files

All processed images are uploaded to Cloudinary:
- **boxed_url:** Original image with bounding boxes
- **mask_url:** Grayscale anomaly heatmap
- **filtered_url:** Filtered image showing only anomalous regions

## πŸ› οΈ Built With

- PyTorch 2.4.1
- Anomalib (PatchCore)
- OpenCV
- Flask
- Cloudinary

## πŸ“„ License

MIT License