vkoottu commited on
Commit
f953306
Β·
verified Β·
1 Parent(s): 7a5665b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +237 -228
README.md CHANGED
@@ -1,229 +1,238 @@
1
- # FaceMatch FastAPI
2
-
3
- A face matching and recommendation system built with FastAPI, InsightFace, and Azure Blob Storage. This application provides personalized face recommendations based on user preferences and similarity matching.
4
-
5
- ## Features
6
-
7
- - **Face Detection & Embedding**: Uses InsightFace for robust face detection and embedding extraction
8
- - **Similarity Matching**: Finds similar faces using cosine similarity on face embeddings
9
- - **Personalized Recommendations**: Learns from user likes/dislikes to provide personalized matches
10
- - **Gender Filtering**: Filter recommendations by gender (male, female, or all)
11
- - **Azure Integration**: Stores images and embeddings in Azure Blob Storage
12
- - **FastAPI**: Modern, fast web framework with automatic API documentation
13
-
14
- ## API Endpoints
15
-
16
- ### Core Endpoints
17
-
18
- - `GET /` - Health check and welcome message
19
- - `POST /api/init_user` - Initialize a new user session
20
- - `GET /api/get_training_images` - Get training images for user preference learning
21
- - `POST /api/record_preference` - Record user like/dislike preferences
22
- - `POST /api/get_matches` - Get personalized matches based on user preferences
23
- - `POST /api/get_recommendations` - Get recommendations based on query images
24
- - `POST /api/extract_embeddings` - Extract embeddings from all images (admin)
25
-
26
- ### API Documentation
27
-
28
- Visit `/docs` for interactive Swagger UI documentation when running locally.
29
-
30
- ## Local Setup
31
-
32
- ### Prerequisites
33
-
34
- - Python 3.8+
35
- - Azure Blob Storage account
36
- - Azure credentials
37
-
38
- ### Installation
39
-
40
- 1. **Clone the repository**
41
- ```bash
42
- git clone <your-repo-url>
43
- cd Facematch_Dev
44
- ```
45
-
46
- 2. **Install dependencies**
47
- ```bash
48
- pip install -r requirements.txt
49
- ```
50
-
51
- 3. **Configure Azure credentials**
52
-
53
- Set your Azure credentials as environment variables:
54
- ```bash
55
- export AZURE_STORAGE_CONNECTION_STRING="your_connection_string"
56
- export AZURE_CONTAINER_NAME="your_container_name"
57
- ```
58
-
59
- Or create a `config.py` file with your credentials.
60
-
61
- 4. **Run the application**
62
- ```bash
63
- python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
64
- ```
65
-
66
- 5. **Access the API**
67
- - API: http://localhost:8000
68
- - Documentation: http://localhost:8000/docs
69
-
70
- ## Usage Examples
71
-
72
- ### Get Recommendations
73
-
74
- **Direct Format:**
75
- ```bash
76
- curl -X POST "http://localhost:8000/api/get_recommendations" \
77
- -H "Content-Type: application/json" \
78
- -d '{
79
- "query_images": [
80
- "https://your-azure-url/image1.jpg",
81
- "https://your-azure-url/image2.jpg"
82
- ],
83
- "gender": "female",
84
- "top_n": 5
85
- }'
86
- ```
87
-
88
- **Hugging Face Format:**
89
- ```bash
90
- curl -X POST "http://localhost:8000/api/get_recommendations" \
91
- -H "Content-Type: application/json" \
92
- -d '{
93
- "inputs": {
94
- "query_images": [
95
- "https://your-azure-url/image1.jpg",
96
- "https://your-azure-url/image2.jpg"
97
- ],
98
- "gender": "female",
99
- "top_n": 5
100
- }
101
- }'
102
- ```
103
-
104
- ### Initialize User Session
105
- ```bash
106
- curl -X POST "http://localhost:8000/api/init_user"
107
- ```
108
-
109
- ### Record Preferences
110
- ```bash
111
- curl -X POST "http://localhost:8000/api/record_preference" \
112
- -H "Content-Type: application/json" \
113
- -d '{
114
- "user_id": "your_user_id",
115
- "image_url": "https://your-azure-url/image.jpg",
116
- "preference": "like"
117
- }'
118
- ```
119
-
120
- ## Hugging Face Spaces Deployment
121
-
122
- ### 1. Create a Hugging Face Space
123
-
124
- 1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
125
- 2. Click "Create new Space"
126
- 3. Choose "FastAPI" as the SDK
127
- 4. Set visibility (public or private)
128
- 5. Create the space
129
-
130
- ### 2. Configure Secrets
131
-
132
- In your Hugging Face Space settings, add these secrets:
133
-
134
- - `AZURE_STORAGE_CONNECTION_STRING`: Your Azure connection string
135
- - `AZURE_CONTAINER_NAME`: Your Azure container name
136
-
137
- ### 3. Upload Files
138
-
139
- Upload these files to your Hugging Face Space:
140
-
141
- - `main.py` - FastAPI application
142
- - `handler.py` - Face matching logic
143
- - `requirements.txt` - Dependencies
144
- - `config.py` - Configuration (if using file-based config)
145
-
146
- ### 4. Deploy
147
-
148
- The space will automatically build and deploy your FastAPI application.
149
-
150
- ### 5. Access Your API
151
-
152
- Your API will be available at:
153
- ```
154
- https://your-username-your-space-name.hf.space
155
- ```
156
-
157
- ## Azure Setup
158
-
159
- ### Required Azure Resources
160
-
161
- 1. **Storage Account**: For storing images and embeddings
162
- 2. **Blob Container**: Organized with folders:
163
- - `ai-images/men/` - Training images for men
164
- - `ai-images/women/` - Training images for women
165
- - `profile-media/` - Images to search for matches
166
-
167
- ### Configuration
168
-
169
- The application expects these Azure settings:
170
-
171
- ```python
172
- # In config.py or environment variables
173
- AZURE_STORAGE_CONNECTION_STRING = "your_connection_string"
174
- AZURE_CONTAINER_NAME = "your_container_name"
175
- ```
176
-
177
- ## File Structure
178
-
179
- ```
180
- Facematch_Dev/
181
- β”œβ”€β”€ main.py # FastAPI application
182
- β”œβ”€β”€ handler.py # Face matching logic
183
- β”œβ”€β”€ config.py # Configuration
184
- β”œβ”€β”€ requirements.txt # Dependencies
185
- β”œβ”€β”€ README.md # This file
186
- β”œβ”€β”€ templates/ # HTML templates (if needed)
187
- └── user_preferences.json # User preferences storage
188
- ```
189
-
190
- ## Performance Notes
191
-
192
- - **Local Development**: Runs on CPU, suitable for testing
193
- - **Hugging Face Spaces**: Runs on GPU, much faster for production
194
- - **Embedding Extraction**: Run `/api/extract_embeddings` after uploading new images
195
- - **Caching**: Embeddings are cached in Azure for faster subsequent queries
196
-
197
- ## Troubleshooting
198
-
199
- ### Common Issues
200
-
201
- 1. **Face Detection Fails**: Some images may not contain detectable faces
202
- 2. **Azure Connection**: Ensure credentials are correctly set
203
- 3. **Memory Issues**: Large image collections may require more memory on Hugging Face
204
-
205
- ### Debug Mode
206
-
207
- Enable debug logging by setting environment variable:
208
- ```bash
209
- export DEBUG=1
210
- ```
211
-
212
- ## Contributing
213
-
214
- 1. Fork the repository
215
- 2. Create a feature branch
216
- 3. Make your changes
217
- 4. Test thoroughly
218
- 5. Submit a pull request
219
-
220
- ## License
221
-
222
- [Add your license information here]
223
-
224
- ## Support
225
-
226
- For issues and questions:
227
- - Create an issue on GitHub
228
- - Check the API documentation at `/docs`
 
 
 
 
 
 
 
 
 
229
  - Review the debug logs for detailed error information
 
1
+ ---
2
+ title: FaceMatch Azure Dev
3
+ emoji: 🐨
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ # FaceMatch FastAPI
11
+
12
+ A face matching and recommendation system built with FastAPI, InsightFace, and Azure Blob Storage. This application provides personalized face recommendations based on user preferences and similarity matching.
13
+
14
+ ## Features
15
+
16
+ - **Face Detection & Embedding**: Uses InsightFace for robust face detection and embedding extraction
17
+ - **Similarity Matching**: Finds similar faces using cosine similarity on face embeddings
18
+ - **Personalized Recommendations**: Learns from user likes/dislikes to provide personalized matches
19
+ - **Gender Filtering**: Filter recommendations by gender (male, female, or all)
20
+ - **Azure Integration**: Stores images and embeddings in Azure Blob Storage
21
+ - **FastAPI**: Modern, fast web framework with automatic API documentation
22
+
23
+ ## API Endpoints
24
+
25
+ ### Core Endpoints
26
+
27
+ - `GET /` - Health check and welcome message
28
+ - `POST /api/init_user` - Initialize a new user session
29
+ - `GET /api/get_training_images` - Get training images for user preference learning
30
+ - `POST /api/record_preference` - Record user like/dislike preferences
31
+ - `POST /api/get_matches` - Get personalized matches based on user preferences
32
+ - `POST /api/get_recommendations` - Get recommendations based on query images
33
+ - `POST /api/extract_embeddings` - Extract embeddings from all images (admin)
34
+
35
+ ### API Documentation
36
+
37
+ Visit `/docs` for interactive Swagger UI documentation when running locally.
38
+
39
+ ## Local Setup
40
+
41
+ ### Prerequisites
42
+
43
+ - Python 3.8+
44
+ - Azure Blob Storage account
45
+ - Azure credentials
46
+
47
+ ### Installation
48
+
49
+ 1. **Clone the repository**
50
+ ```bash
51
+ git clone <your-repo-url>
52
+ cd Facematch_Dev
53
+ ```
54
+
55
+ 2. **Install dependencies**
56
+ ```bash
57
+ pip install -r requirements.txt
58
+ ```
59
+
60
+ 3. **Configure Azure credentials**
61
+
62
+ Set your Azure credentials as environment variables:
63
+ ```bash
64
+ export AZURE_STORAGE_CONNECTION_STRING="your_connection_string"
65
+ export AZURE_CONTAINER_NAME="your_container_name"
66
+ ```
67
+
68
+ Or create a `config.py` file with your credentials.
69
+
70
+ 4. **Run the application**
71
+ ```bash
72
+ python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000
73
+ ```
74
+
75
+ 5. **Access the API**
76
+ - API: http://localhost:8000
77
+ - Documentation: http://localhost:8000/docs
78
+
79
+ ## Usage Examples
80
+
81
+ ### Get Recommendations
82
+
83
+ **Direct Format:**
84
+ ```bash
85
+ curl -X POST "http://localhost:8000/api/get_recommendations" \
86
+ -H "Content-Type: application/json" \
87
+ -d '{
88
+ "query_images": [
89
+ "https://your-azure-url/image1.jpg",
90
+ "https://your-azure-url/image2.jpg"
91
+ ],
92
+ "gender": "female",
93
+ "top_n": 5
94
+ }'
95
+ ```
96
+
97
+ **Hugging Face Format:**
98
+ ```bash
99
+ curl -X POST "http://localhost:8000/api/get_recommendations" \
100
+ -H "Content-Type: application/json" \
101
+ -d '{
102
+ "inputs": {
103
+ "query_images": [
104
+ "https://your-azure-url/image1.jpg",
105
+ "https://your-azure-url/image2.jpg"
106
+ ],
107
+ "gender": "female",
108
+ "top_n": 5
109
+ }
110
+ }'
111
+ ```
112
+
113
+ ### Initialize User Session
114
+ ```bash
115
+ curl -X POST "http://localhost:8000/api/init_user"
116
+ ```
117
+
118
+ ### Record Preferences
119
+ ```bash
120
+ curl -X POST "http://localhost:8000/api/record_preference" \
121
+ -H "Content-Type: application/json" \
122
+ -d '{
123
+ "user_id": "your_user_id",
124
+ "image_url": "https://your-azure-url/image.jpg",
125
+ "preference": "like"
126
+ }'
127
+ ```
128
+
129
+ ## Hugging Face Spaces Deployment
130
+
131
+ ### 1. Create a Hugging Face Space
132
+
133
+ 1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
134
+ 2. Click "Create new Space"
135
+ 3. Choose "FastAPI" as the SDK
136
+ 4. Set visibility (public or private)
137
+ 5. Create the space
138
+
139
+ ### 2. Configure Secrets
140
+
141
+ In your Hugging Face Space settings, add these secrets:
142
+
143
+ - `AZURE_STORAGE_CONNECTION_STRING`: Your Azure connection string
144
+ - `AZURE_CONTAINER_NAME`: Your Azure container name
145
+
146
+ ### 3. Upload Files
147
+
148
+ Upload these files to your Hugging Face Space:
149
+
150
+ - `main.py` - FastAPI application
151
+ - `handler.py` - Face matching logic
152
+ - `requirements.txt` - Dependencies
153
+ - `config.py` - Configuration (if using file-based config)
154
+
155
+ ### 4. Deploy
156
+
157
+ The space will automatically build and deploy your FastAPI application.
158
+
159
+ ### 5. Access Your API
160
+
161
+ Your API will be available at:
162
+ ```
163
+ https://your-username-your-space-name.hf.space
164
+ ```
165
+
166
+ ## Azure Setup
167
+
168
+ ### Required Azure Resources
169
+
170
+ 1. **Storage Account**: For storing images and embeddings
171
+ 2. **Blob Container**: Organized with folders:
172
+ - `ai-images/men/` - Training images for men
173
+ - `ai-images/women/` - Training images for women
174
+ - `profile-media/` - Images to search for matches
175
+
176
+ ### Configuration
177
+
178
+ The application expects these Azure settings:
179
+
180
+ ```python
181
+ # In config.py or environment variables
182
+ AZURE_STORAGE_CONNECTION_STRING = "your_connection_string"
183
+ AZURE_CONTAINER_NAME = "your_container_name"
184
+ ```
185
+
186
+ ## File Structure
187
+
188
+ ```
189
+ Facematch_Dev/
190
+ β”œβ”€β”€ main.py # FastAPI application
191
+ β”œβ”€β”€ handler.py # Face matching logic
192
+ β”œβ”€β”€ config.py # Configuration
193
+ β”œβ”€β”€ requirements.txt # Dependencies
194
+ β”œβ”€β”€ README.md # This file
195
+ β”œβ”€β”€ templates/ # HTML templates (if needed)
196
+ └── user_preferences.json # User preferences storage
197
+ ```
198
+
199
+ ## Performance Notes
200
+
201
+ - **Local Development**: Runs on CPU, suitable for testing
202
+ - **Hugging Face Spaces**: Runs on GPU, much faster for production
203
+ - **Embedding Extraction**: Run `/api/extract_embeddings` after uploading new images
204
+ - **Caching**: Embeddings are cached in Azure for faster subsequent queries
205
+
206
+ ## Troubleshooting
207
+
208
+ ### Common Issues
209
+
210
+ 1. **Face Detection Fails**: Some images may not contain detectable faces
211
+ 2. **Azure Connection**: Ensure credentials are correctly set
212
+ 3. **Memory Issues**: Large image collections may require more memory on Hugging Face
213
+
214
+ ### Debug Mode
215
+
216
+ Enable debug logging by setting environment variable:
217
+ ```bash
218
+ export DEBUG=1
219
+ ```
220
+
221
+ ## Contributing
222
+
223
+ 1. Fork the repository
224
+ 2. Create a feature branch
225
+ 3. Make your changes
226
+ 4. Test thoroughly
227
+ 5. Submit a pull request
228
+
229
+ ## License
230
+
231
+ [Add your license information here]
232
+
233
+ ## Support
234
+
235
+ For issues and questions:
236
+ - Create an issue on GitHub
237
+ - Check the API documentation at `/docs`
238
  - Review the debug logs for detailed error information