Spaces:
Runtime error
Runtime error
Update demo.py
Browse files
demo.py
CHANGED
|
@@ -3,6 +3,7 @@ import requests
|
|
| 3 |
import datadog_api_client
|
| 4 |
import json
|
| 5 |
import io
|
|
|
|
| 6 |
|
| 7 |
from PIL import Image
|
| 8 |
|
|
@@ -32,6 +33,22 @@ def face_crop(image, face_rect):
|
|
| 32 |
face_image = face_image.resize((int(resized_w), int(resized_h)))
|
| 33 |
return face_image
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def compare_face(frame1, frame2):
|
| 36 |
url = "http://127.0.0.1:8080/compare_face"
|
| 37 |
files = {'file1': open(frame1, 'rb'), 'file2': open(frame2, 'rb')}
|
|
|
|
| 3 |
import datadog_api_client
|
| 4 |
import json
|
| 5 |
import io
|
| 6 |
+
import base64
|
| 7 |
|
| 8 |
from PIL import Image
|
| 9 |
|
|
|
|
| 33 |
face_image = face_image.resize((int(resized_w), int(resized_h)))
|
| 34 |
return face_image
|
| 35 |
|
| 36 |
+
def pil_image_to_base64(image, format="PNG"):
|
| 37 |
+
"""
|
| 38 |
+
Converts a PIL.Image object to a Base64-encoded string.
|
| 39 |
+
:param image: PIL.Image object
|
| 40 |
+
:param format: Format to save the image, e.g., "PNG", "JPEG"
|
| 41 |
+
:return: Base64-encoded string
|
| 42 |
+
"""
|
| 43 |
+
# Save the image to a BytesIO buffer
|
| 44 |
+
buffer = io.BytesIO()
|
| 45 |
+
image.save(buffer, format=format)
|
| 46 |
+
buffer.seek(0) # Rewind the buffer
|
| 47 |
+
|
| 48 |
+
# Convert the buffer's contents to a Base64 string
|
| 49 |
+
base64_string = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 50 |
+
return base64_string
|
| 51 |
+
|
| 52 |
def compare_face(frame1, frame2):
|
| 53 |
url = "http://127.0.0.1:8080/compare_face"
|
| 54 |
files = {'file1': open(frame1, 'rb'), 'file2': open(frame2, 'rb')}
|