Add Hugging Face Space config in README
Browse files
README.md
CHANGED
|
@@ -1,115 +1,23 @@
|
|
| 1 |
-
# π¦ FastAPI Inference Server
|
| 2 |
-
|
| 3 |
-
A blazing-fast inference server for computer vision tasks using FastAPI, YOLO, DINOv2, and FAISS! π
|
| 4 |
-
|
| 5 |
-
## Features
|
| 6 |
-
- **YOLOv8 Segmentation**: Detect and segment objects in images
|
| 7 |
-
- **DINOv2 Embeddings**: Extract powerful image features
|
| 8 |
-
- **FAISS Vector Search**: Find similar items using vector search
|
| 9 |
-
- **Easy REST API**: Simple endpoints for integration with any frontend
|
| 10 |
-
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
## π οΈ Setup
|
| 14 |
-
|
| 15 |
-
### 1. Clone the repository
|
| 16 |
-
```bash
|
| 17 |
-
git clone <your-repo-url>
|
| 18 |
-
cd <your-project-directory>
|
| 19 |
-
```
|
| 20 |
-
|
| 21 |
-
### 2. Install dependencies
|
| 22 |
-
```bash
|
| 23 |
-
pip install -r requirements.txt
|
| 24 |
-
```
|
| 25 |
-
|
| 26 |
-
### 3. Download/Place Model Files
|
| 27 |
-
- Place your YOLO model at `models/deepfashion2_yolov8s-seg.pt`
|
| 28 |
-
- Place your FAISS index and metadata at `index/jersey_index.faiss` and `index/jersey_metadata.npy`
|
| 29 |
-
|
| 30 |
-
### 4. Start the server
|
| 31 |
-
```bash
|
| 32 |
-
uvicorn inference_server:app --host 0.0.0.0 --port 8000 --reload
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
---
|
| 36 |
-
|
| 37 |
-
## π₯ API Endpoints
|
| 38 |
-
|
| 39 |
-
### `POST /yolo`
|
| 40 |
-
- **Description:** Run YOLOv8 segmentation on an image
|
| 41 |
-
- **Request:** Multipart/form-data with an image file
|
| 42 |
-
- **Response:** JSON with detected polygons
|
| 43 |
-
|
| 44 |
-
### `POST /dino`
|
| 45 |
-
- **Description:** Extract DINOv2 features from an image
|
| 46 |
-
- **Request:** Multipart/form-data with an image file
|
| 47 |
-
- **Response:** JSON with feature vector
|
| 48 |
-
|
| 49 |
-
### `POST /faiss`
|
| 50 |
-
- **Description:** Search for similar items using FAISS
|
| 51 |
-
- **Request:** JSON with `features` (list of floats)
|
| 52 |
-
- **Response:** JSON with ranked search results
|
| 53 |
-
|
| 54 |
---
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
with open('your_image.jpg', 'rb') as f:
|
| 63 |
-
response = requests.post('http://localhost:8000/yolo', files={'file': f})
|
| 64 |
-
print(response.json())
|
| 65 |
-
```
|
| 66 |
-
|
| 67 |
-
### DINOv2 Inference (Python)
|
| 68 |
-
```python
|
| 69 |
-
import requests
|
| 70 |
-
|
| 71 |
-
with open('your_image.jpg', 'rb') as f:
|
| 72 |
-
response = requests.post('http://localhost:8000/dino', files={'file': f})
|
| 73 |
-
print(response.json())
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
### FAISS Search (Python)
|
| 77 |
-
```python
|
| 78 |
-
import requests
|
| 79 |
-
features = [0.1, 0.2, ...] # Replace with your feature vector
|
| 80 |
-
response = requests.post('http://localhost:8000/faiss', json={'features': features})
|
| 81 |
-
print(response.json())
|
| 82 |
-
```
|
| 83 |
-
|
| 84 |
---
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
If using a frontend on a different port, make sure to enable CORS in `inference_server.py`:
|
| 88 |
-
```python
|
| 89 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 90 |
-
app.add_middleware(
|
| 91 |
-
CORSMiddleware,
|
| 92 |
-
allow_origins=["https://localhost:8081"],
|
| 93 |
-
allow_credentials=True,
|
| 94 |
-
allow_methods=["*"],
|
| 95 |
-
allow_headers=["*"],
|
| 96 |
-
)
|
| 97 |
-
```
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
## π Project Structure
|
| 102 |
-
```
|
| 103 |
-
βββ inference_server.py # FastAPI app and endpoints
|
| 104 |
-
βββ requirements.txt # Python dependencies
|
| 105 |
-
βββ models/
|
| 106 |
-
β βββ deepfashion2_yolov8s-seg.pt
|
| 107 |
-
βββ index/
|
| 108 |
-
β βββ jersey_index.faiss
|
| 109 |
-
β βββ jersey_metadata.npy
|
| 110 |
-
```
|
| 111 |
|
| 112 |
-
---
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Devam Jersey Server
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_file: inference_server.py
|
| 8 |
+
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Devam Jersey Server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
This Space runs my custom inference server for **jersey similarity and detection**.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
- **Model**: YOLOv8s-seg (fine-tuned on DeepFashion2)
|
| 16 |
+
- **Indexing**: FAISS index for jersey embeddings
|
| 17 |
+
- **Backend**: `inference_server.py` served with Docker
|
| 18 |
+
- **Data**: Jersey metadata stored in `.npy` and FAISS index file
|
| 19 |
|
| 20 |
+
The server can:
|
| 21 |
+
- Detect jersey regions
|
| 22 |
+
- Extract embeddings
|
| 23 |
+
- Search most visually similar designs
|