Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import cv2
|
|
@@ -6,7 +12,6 @@ import numpy as np
|
|
| 6 |
import base64
|
| 7 |
from io import BytesIO
|
| 8 |
from PIL import Image
|
| 9 |
-
import os
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
CORS(app)
|
|
@@ -43,7 +48,7 @@ def predict_emotion():
|
|
| 43 |
# convertir a escala de grises
|
| 44 |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 45 |
# convertir a RGB para DeepFace
|
| 46 |
-
rgb_frame = cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2RGB)
|
| 47 |
# detectar rostros en el frame
|
| 48 |
faces = face_cascade.detectMultiScale(
|
| 49 |
gray_frame,
|
|
@@ -59,14 +64,14 @@ def predict_emotion():
|
|
| 59 |
# si se detectaron rostros
|
| 60 |
if len(faces) > 0:
|
| 61 |
for (x, y, w, h) in faces:
|
| 62 |
-
#
|
| 63 |
-
face_roi = rgb_frame[y:y + h, x:x + w]
|
| 64 |
# realizar an谩lisis de emoci贸n
|
| 65 |
result = DeepFace.analyze(
|
| 66 |
face_roi,
|
| 67 |
actions=['emotion'],
|
| 68 |
enforce_detection=False
|
| 69 |
-
)
|
| 70 |
# determinar la emoci贸n dominante
|
| 71 |
emocion = result[0]['dominant_emotion']
|
| 72 |
all_emotions = result[0]['emotion']
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# Configurar variables de entorno para DeepFace ANTES de importar
|
| 4 |
+
os.environ['HOME'] = '/tmp'
|
| 5 |
+
os.environ['DEEPFACE_HOME'] = '/tmp/.deepface'
|
| 6 |
+
|
| 7 |
from flask import Flask, request, jsonify
|
| 8 |
from flask_cors import CORS
|
| 9 |
import cv2
|
|
|
|
| 12 |
import base64
|
| 13 |
from io import BytesIO
|
| 14 |
from PIL import Image
|
|
|
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
| 17 |
CORS(app)
|
|
|
|
| 48 |
# convertir a escala de grises
|
| 49 |
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
| 50 |
# convertir a RGB para DeepFace
|
| 51 |
+
rgb_frame = cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2RGB)
|
| 52 |
# detectar rostros en el frame
|
| 53 |
faces = face_cascade.detectMultiScale(
|
| 54 |
gray_frame,
|
|
|
|
| 64 |
# si se detectaron rostros
|
| 65 |
if len(faces) > 0:
|
| 66 |
for (x, y, w, h) in faces:
|
| 67 |
+
# extraer la regi贸n del rostro
|
| 68 |
+
face_roi = rgb_frame[y:y + h, x:x + w]
|
| 69 |
# realizar an谩lisis de emoci贸n
|
| 70 |
result = DeepFace.analyze(
|
| 71 |
face_roi,
|
| 72 |
actions=['emotion'],
|
| 73 |
enforce_detection=False
|
| 74 |
+
)
|
| 75 |
# determinar la emoci贸n dominante
|
| 76 |
emocion = result[0]['dominant_emotion']
|
| 77 |
all_emotions = result[0]['emotion']
|