Spaces:
Sleeping
Sleeping
Create modeles/template_generator.py
Browse files
modeles/template_generator.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modeles/template_generator.py
|
| 2 |
+
|
| 3 |
+
#on va générer les ficheir binaire de nos images : nos embedding auquel on comparera nos vidéo pour identifier si c'est la bonne personne
|
| 4 |
+
import tempfile
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
import numpy as np
|
| 8 |
+
from fastapi.responses import JSONResponse
|
| 9 |
+
from modeles import deepface_template_utils as dtu
|
| 10 |
+
#on a créer une fonction dans deepface_template_utils qui génère ces embedding : on l'appelle
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def generate_template_from_image(image_bytes):
|
| 14 |
+
# Créer un dossier temporaire
|
| 15 |
+
temp_dir = tempfile.mkdtemp()
|
| 16 |
+
image_path = os.path.join(temp_dir, "image.jpg")
|
| 17 |
+
|
| 18 |
+
with open(image_path, "wb") as f:
|
| 19 |
+
f.write(image_bytes)
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
# Appel de ta fonction existante
|
| 23 |
+
template_array = dtu.create_template_from_folder(temp_dir)
|
| 24 |
+
|
| 25 |
+
# Supprimer le dossier temporaire
|
| 26 |
+
shutil.rmtree(temp_dir)
|
| 27 |
+
|
| 28 |
+
# Retourner le template au format JSON
|
| 29 |
+
return JSONResponse(content={"template": template_array.tolist()})
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
shutil.rmtree(temp_dir)
|
| 33 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|