|
98 | 98 | "client.create_person_directory(person_directory_id)\n",
|
99 | 99 | "logging.info(f\"Created person directory with ID: {person_directory_id}\")\n",
|
100 | 100 | "\n",
|
| 101 | + "# Initialize persons list\n", |
| 102 | + "persons: list = []\n", |
| 103 | + "\n", |
101 | 104 | "# Iterate through all subfolders in the folder_path\n",
|
102 | 105 | "for subfolder_name in os.listdir(folder_path):\n",
|
103 | 106 | " subfolder_path = os.path.join(folder_path, subfolder_name)\n",
|
|
107 | 110 | " person = client.add_person(person_directory_id, tags={\"name\": person_name})\n",
|
108 | 111 | " logging.info(f\"Created person {person_name} with person_id: {person['personId']}\")\n",
|
109 | 112 | " if person:\n",
|
| 113 | + " # Initialize person entry in persons list\n", |
| 114 | + " person_entry = {\n", |
| 115 | + " 'personId': person['personId'],\n", |
| 116 | + " 'name': person_name,\n", |
| 117 | + " 'faceIds': []\n", |
| 118 | + " }\n", |
110 | 119 | " # Iterate through all images in the subfolder\n",
|
111 | 120 | " for filename in os.listdir(subfolder_path):\n",
|
112 | 121 | " if filename.lower().endswith(('.png', '.jpg', '.jpeg')):\n",
|
|
116 | 125 | " # Add a face to the Person Directory and associate it to the added person\n",
|
117 | 126 | " face = client.add_face(person_directory_id, image_data, person['personId'])\n",
|
118 | 127 | " if face:\n",
|
| 128 | + " # Add face ID to the person's faceIds list\n", |
| 129 | + " person_entry['faceIds'].append(face['faceId'])\n", |
119 | 130 | " logging.info(f\"Added face from {filename} with face_id: {face['faceId']} to person_id: {person['personId']}\")\n",
|
120 | 131 | " else:\n",
|
121 | 132 | " logging.warning(f\"Failed to add face from {filename} to person_id: {person['personId']}\")\n",
|
122 | 133 | "\n",
|
123 |
| - "logging.info(\"Done\")" |
| 134 | + " # Add person entry to persons list\n", |
| 135 | + " persons.append(person_entry)\n", |
| 136 | + "\n", |
| 137 | + "logging.info(\"Done\")\n", |
| 138 | + "logging.info(f\"Created {len(persons)} persons:\")\n", |
| 139 | + "for person in persons:\n", |
| 140 | + " logging.info(f\"Person: {person['name']} (ID: {person['personId']}) with {len(person['faceIds'])} faces\")" |
124 | 141 | ]
|
125 | 142 | },
|
126 | 143 | {
|
|
170 | 187 | "metadata": {},
|
171 | 188 | "outputs": [],
|
172 | 189 | "source": [
|
173 |
| - "new_face_image_path = \"new_face_image_path\" # The path to the face image you want to add.\n", |
174 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to whom the face should be associated.\n", |
| 190 | + "person_bill = next(person for person in persons if person['name'] == 'Bill')\n", |
| 191 | + "new_face_image_path = \"../data/face/new_face_image.jpg\" # The path to the face image you want to add.\n", |
| 192 | + "existing_person_id = person_bill['personId'] # The unique ID of the person to whom the face should be associated.\n", |
175 | 193 | "\n",
|
176 | 194 | "# Convert the new face image to base64\n",
|
177 | 195 | "image_data = AzureContentUnderstandingFaceClient.read_file_to_base64(new_face_image_path)\n",
|
|
200 | 218 | "metadata": {},
|
201 | 219 | "outputs": [],
|
202 | 220 | "source": [
|
203 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to whom the face should be associated.\n", |
204 |
| - "existing_face_id_list = [\"existing_face_id_1\", \"existing_face_id_2\"] # The list of face IDs to be associated.\n", |
| 221 | + "existing_person_id = person_bill['personId'] # The unique ID of the person to whom the face should be associated.\n", |
| 222 | + "existing_face_id_list = person_bill['faceIds'] # The list of face IDs to be associated.\n", |
205 | 223 | "\n",
|
206 | 224 | "# Associate the existing face IDs with the existing person\n",
|
207 | 225 | "client.update_person(person_directory_id, existing_person_id, face_ids=existing_face_id_list)"
|
|
223 | 241 | "metadata": {},
|
224 | 242 | "outputs": [],
|
225 | 243 | "source": [
|
226 |
| - "existing_face_id = \"existing_face_id\" # The unique ID of the face.\n", |
| 244 | + "person_mary = next(person for person in persons if person['name'] == 'Mary')\n", |
| 245 | + "existing_face_id = person_mary['faceIds'][0] # The unique ID of the face.\n", |
227 | 246 | "\n",
|
228 | 247 | "# Remove the association of the existing face ID from the person\n",
|
229 | 248 | "client.update_face(person_directory_id, existing_face_id, person_id=\"\") # The person_id is set to \"\" to remove the association\n",
|
230 | 249 | "logging.info(f\"Removed association of face_id: {existing_face_id} from the existing person_id\")\n",
|
231 | 250 | "logging.info(client.get_face(person_directory_id, existing_face_id)) # This will return the face information without the person association\n",
|
232 | 251 | "\n",
|
233 | 252 | "# Associate the existing face ID with a person\n",
|
234 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to be associated with the face.\n", |
| 253 | + "person_jordan = next(person for person in persons if person['name'] == 'Jordan')\n", |
| 254 | + "existing_person_id = person_jordan['personId'] # The unique ID of the person to be associated with the face.\n", |
235 | 255 | "client.update_face(person_directory_id, existing_face_id, person_id=existing_person_id)\n",
|
236 | 256 | "logging.info(f\"Associated face_id: {existing_face_id} with person_id: {existing_person_id}\")\n",
|
237 | 257 | "logging.info(client.get_face(person_directory_id, existing_face_id)) # This will return the face information with the new person association"
|
|
266 | 286 | "logging.info(client.get_person_directory(person_directory_id)) # This will return the updated person directory information\n",
|
267 | 287 | "\n",
|
268 | 288 | "# Update the tags for an individual person\n",
|
269 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to update.\n", |
| 289 | + "existing_person_id = person_bill['personId'] # The unique ID of the person to update.\n", |
270 | 290 | "person_tags = {\"role\": \"tester\", \"department\": \"engineering\", \"name\": \"\"} # This will remove the name tag from the person.\n",
|
271 | 291 | "\n",
|
272 | 292 | "client.update_person(\n",
|
|
294 | 314 | "metadata": {},
|
295 | 315 | "outputs": [],
|
296 | 316 | "source": [
|
297 |
| - "existing_face_id = \"existing_face_id\" # The unique ID of the face to delete.\n", |
| 317 | + "existing_face_id = person_mary['faceIds'][0] # The unique ID of the face to delete.\n", |
298 | 318 | "\n",
|
299 | 319 | "client.delete_face(person_directory_id, existing_face_id)\n",
|
300 | 320 | "logging.info(f\"Deleted face with face_id: {existing_face_id}\")"
|
|
317 | 337 | "metadata": {},
|
318 | 338 | "outputs": [],
|
319 | 339 | "source": [
|
320 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to delete.\n", |
| 340 | + "existing_person_id = person_mary['personId'] # The unique ID of the person to delete.\n", |
321 | 341 | "\n",
|
322 | 342 | "client.delete_person(person_directory_id, existing_person_id)\n",
|
323 | 343 | "logging.info(f\"Deleted person with person_id: {existing_person_id}\")"
|
|
340 | 360 | "metadata": {},
|
341 | 361 | "outputs": [],
|
342 | 362 | "source": [
|
343 |
| - "existing_person_id = \"existing_person_id\" # The unique ID of the person to delete.\n", |
| 363 | + "existing_person_id = person_bill['personId'] # The unique ID of the person to delete.\n", |
344 | 364 | "\n",
|
345 | 365 | "# Get the list of face IDs associated with the person\n",
|
346 | 366 | "response = client.get_person(person_directory_id, existing_person_id)\n",
|
|
373 | 393 | "name": "python",
|
374 | 394 | "nbconvert_exporter": "python",
|
375 | 395 | "pygments_lexer": "ipython3",
|
376 |
| - "version": "3.11.12" |
| 396 | + "version": "3.13.7" |
377 | 397 | }
|
378 | 398 | },
|
379 | 399 | "nbformat": 4,
|
|
0 commit comments