Spaces:
Sleeping
Sleeping
File size: 1,111 Bytes
90db32e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # modeles/template_generator.py
#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
import tempfile
import os
import shutil
import numpy as np
from fastapi.responses import JSONResponse
from modeles import deepface_template_utils as dtu
#on a créer une fonction dans deepface_template_utils qui génère ces embedding : on l'appelle
def generate_template_from_image(image_bytes):
# Créer un dossier temporaire
temp_dir = tempfile.mkdtemp()
image_path = os.path.join(temp_dir, "image.jpg")
with open(image_path, "wb") as f:
f.write(image_bytes)
try:
# Appel de ta fonction existante
template_array = dtu.create_template_from_folder(temp_dir)
# Supprimer le dossier temporaire
shutil.rmtree(temp_dir)
# Retourner le template au format JSON
return JSONResponse(content={"template": template_array.tolist()})
except Exception as e:
shutil.rmtree(temp_dir)
return JSONResponse(content={"error": str(e)}, status_code=500)
|