Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
import os
|
| 5 |
import joblib
|
| 6 |
import numpy as np
|
|
@@ -72,9 +71,6 @@ def predict_face(img):
|
|
| 72 |
print("DeepFace.analyze error:", e)
|
| 73 |
return {}
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
def predict_voice(audio_path: str):
|
| 79 |
# 如果没有录音文件路径,直接返回空字典或提示
|
| 80 |
if not audio_path:
|
|
@@ -91,9 +87,6 @@ def predict_voice(audio_path: str):
|
|
| 91 |
except Exception as e:
|
| 92 |
print("predict_voice error:", e)
|
| 93 |
return {}
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
def predict_text_mixed(text: str):
|
| 99 |
"""
|
|
@@ -131,10 +124,6 @@ def predict_text_mixed(text: str):
|
|
| 131 |
print("zero-shot error:", e)
|
| 132 |
return {"中性": 1.0}
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
# --- 5. 建立 Gradio 介面 ---
|
| 139 |
with gr.Blocks() as demo:
|
| 140 |
with gr.TabItem("臉部情緒"):
|
|
@@ -143,9 +132,6 @@ with gr.Blocks() as demo:
|
|
| 143 |
face_out = gr.Label(label="情緒分布")
|
| 144 |
webcam.stream(fn=predict_face, inputs=webcam, outputs=face_out)
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
# 其餘 Tab 可按原先寫法,或用 Blocks 方式
|
| 150 |
with gr.TabItem("語音情緒"):
|
| 151 |
audio = gr.Audio(sources="microphone", streaming=False, type="filepath", label="錄音")
|
|
@@ -159,10 +145,6 @@ with gr.Blocks() as demo:
|
|
| 159 |
text = gr.Textbox(lines=3, placeholder="請輸入中文文字…")
|
| 160 |
text_out = gr.Label(label="文字情緒結果")
|
| 161 |
text.submit(fn=predict_text_mixed, inputs=text, outputs=text_out)
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
if __name__ == "__main__":
|
| 167 |
|
| 168 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
print("Gradio version:", gr.__version__)
|
|
|
|
| 3 |
import os
|
| 4 |
import joblib
|
| 5 |
import numpy as np
|
|
|
|
| 71 |
print("DeepFace.analyze error:", e)
|
| 72 |
return {}
|
| 73 |
|
|
|
|
|
|
|
|
|
|
| 74 |
def predict_voice(audio_path: str):
|
| 75 |
# 如果没有录音文件路径,直接返回空字典或提示
|
| 76 |
if not audio_path:
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
print("predict_voice error:", e)
|
| 89 |
return {}
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
def predict_text_mixed(text: str):
|
| 92 |
"""
|
|
|
|
| 124 |
print("zero-shot error:", e)
|
| 125 |
return {"中性": 1.0}
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# --- 5. 建立 Gradio 介面 ---
|
| 128 |
with gr.Blocks() as demo:
|
| 129 |
with gr.TabItem("臉部情緒"):
|
|
|
|
| 132 |
face_out = gr.Label(label="情緒分布")
|
| 133 |
webcam.stream(fn=predict_face, inputs=webcam, outputs=face_out)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
| 135 |
# 其餘 Tab 可按原先寫法,或用 Blocks 方式
|
| 136 |
with gr.TabItem("語音情緒"):
|
| 137 |
audio = gr.Audio(sources="microphone", streaming=False, type="filepath", label="錄音")
|
|
|
|
| 145 |
text = gr.Textbox(lines=3, placeholder="請輸入中文文字…")
|
| 146 |
text_out = gr.Label(label="文字情緒結果")
|
| 147 |
text.submit(fn=predict_text_mixed, inputs=text, outputs=text_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
if __name__ == "__main__":
|
| 149 |
|
| 150 |
demo.launch()
|