Spaces:
Sleeping
Sleeping
Commit
·
fc8319f
1
Parent(s):
b40ebf5
Fix SocketIO CORS origin
Browse files- backend/server.py +6 -4
backend/server.py
CHANGED
|
@@ -23,10 +23,11 @@ except Exception as e:
|
|
| 23 |
print(f"❌ Erreur connexion Supabase : {e}")
|
| 24 |
|
| 25 |
# --- CONFIGURATION SERVEUR & SÉCURITÉ (CORS) ---
|
| 26 |
-
# C'EST ICI LA CORRECTION CRITIQUE :
|
| 27 |
-
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*')
|
| 28 |
|
| 29 |
app = FastAPI()
|
|
|
|
| 30 |
app.add_middleware(
|
| 31 |
CORSMiddleware,
|
| 32 |
allow_origins=["*"],
|
|
@@ -57,7 +58,7 @@ def delete_session(session_id: int):
|
|
| 57 |
except Exception as e:
|
| 58 |
raise HTTPException(status_code=500, detail=str(e))
|
| 59 |
|
| 60 |
-
# --- LOGIQUE MÉTIER ---
|
| 61 |
def calculate_kpis(emotion):
|
| 62 |
valence = 0.0; arousal = 0.0; noise = random.uniform(-0.05, 0.05)
|
| 63 |
if emotion == "happy": valence = 0.8 + noise; arousal = 0.6 + noise
|
|
@@ -99,6 +100,7 @@ async def process_frame(sid, data_uri):
|
|
| 99 |
nparr = np.frombuffer(base64.b64decode(encoded_data), np.uint8)
|
| 100 |
frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 101 |
|
|
|
|
| 102 |
result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False, silent=True)
|
| 103 |
data = result[0] if isinstance(result, list) else result
|
| 104 |
|
|
@@ -140,7 +142,7 @@ async def session_manager_loop():
|
|
| 140 |
"session_time": user_data["session_time"],
|
| 141 |
"is_recording": user_data["is_recording"]
|
| 142 |
}, room=sid)
|
| 143 |
-
await asyncio.sleep(1)
|
| 144 |
|
| 145 |
@sio.event
|
| 146 |
async def connect(sid, environ):
|
|
|
|
| 23 |
print(f"❌ Erreur connexion Supabase : {e}")
|
| 24 |
|
| 25 |
# --- CONFIGURATION SERVEUR & SÉCURITÉ (CORS) ---
|
| 26 |
+
# C'EST ICI LA CORRECTION CRITIQUE (LIGNE 25) :
|
| 27 |
+
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins='*')
|
| 28 |
|
| 29 |
app = FastAPI()
|
| 30 |
+
# Middleware pour autoriser les requêtes API REST classiques
|
| 31 |
app.add_middleware(
|
| 32 |
CORSMiddleware,
|
| 33 |
allow_origins=["*"],
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
raise HTTPException(status_code=500, detail=str(e))
|
| 60 |
|
| 61 |
+
# --- LOGIQUE MÉTIER (DeepFace + KPIs) ---
|
| 62 |
def calculate_kpis(emotion):
|
| 63 |
valence = 0.0; arousal = 0.0; noise = random.uniform(-0.05, 0.05)
|
| 64 |
if emotion == "happy": valence = 0.8 + noise; arousal = 0.6 + noise
|
|
|
|
| 100 |
nparr = np.frombuffer(base64.b64decode(encoded_data), np.uint8)
|
| 101 |
frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 102 |
|
| 103 |
+
# Analyse DeepFace
|
| 104 |
result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False, silent=True)
|
| 105 |
data = result[0] if isinstance(result, list) else result
|
| 106 |
|
|
|
|
| 142 |
"session_time": user_data["session_time"],
|
| 143 |
"is_recording": user_data["is_recording"]
|
| 144 |
}, room=sid)
|
| 145 |
+
await asyncio.sleep(1) # Mise à jour chaque seconde
|
| 146 |
|
| 147 |
@sio.event
|
| 148 |
async def connect(sid, environ):
|