Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,24 @@
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
-
import numpy as np
|
| 5 |
import base64, io, os
|
| 6 |
import librosa, joblib
|
| 7 |
from deepface import DeepFace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# —— 1. 预加载 DeepFace、语音模型 ——
|
| 10 |
# DeepFace 会自动把权重缓存到 DEEPFACE_HOME 下的 /weights
|
|
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
+
import cv2, numpy as np
|
| 5 |
import base64, io, os
|
| 6 |
import librosa, joblib
|
| 7 |
from deepface import DeepFace
|
| 8 |
+
def analyze_frame(frame):
|
| 9 |
+
# frame 是一張 RGB numpy 圖
|
| 10 |
+
result = DeepFace.analyze(frame, actions=['emotion'])
|
| 11 |
+
return result['dominant_emotion']
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=analyze_frame,
|
| 15 |
+
inputs=gr.inputs.Image(source="webcam", tool=None),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="多模態即時情緒分析"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
iface.launch()
|
| 22 |
|
| 23 |
# —— 1. 预加载 DeepFace、语音模型 ——
|
| 24 |
# DeepFace 会自动把权重缓存到 DEEPFACE_HOME 下的 /weights
|