Update src/emotion_detector.py
Browse files- src/emotion_detector.py +14 -6
src/emotion_detector.py
CHANGED
@@ -1,16 +1,24 @@
|
|
1 |
# emotion_detector.py
|
2 |
-
import torchaudio
|
3 |
-
from speechbrain.inference.classifiers import AudioClassifier
|
4 |
import os
|
|
|
5 |
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
# Use a temp directory
|
8 |
-
|
9 |
|
10 |
-
# Load pretrained model
|
11 |
classifier = AudioClassifier.from_hparams(
|
12 |
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
13 |
-
savedir=
|
14 |
)
|
15 |
|
16 |
EMOTION_EMOJIS = {
|
|
|
1 |
# emotion_detector.py
|
|
|
|
|
2 |
import os
|
3 |
+
import torchaudio
|
4 |
import tempfile
|
5 |
+
from speechbrain.inference.classifiers import AudioClassifier
|
6 |
+
|
7 |
+
# Set HF_HOME to writable temp directory
|
8 |
+
os.environ["HF_HOME"] = os.path.join(tempfile.gettempdir(), "hf_cache")
|
9 |
+
|
10 |
+
# Also set Hugging Face cache dir explicitly (optional but helps)
|
11 |
+
os.environ["HF_DATASETS_CACHE"] = os.environ["HF_HOME"]
|
12 |
+
os.environ["TRANSFORMERS_CACHE"] = os.environ["HF_HOME"]
|
13 |
+
os.environ["HUGGINGFACE_HUB_CACHE"] = os.environ["HF_HOME"]
|
14 |
|
15 |
+
# Use a temp directory for SpeechBrain model saving
|
16 |
+
model_dir = os.path.join(tempfile.gettempdir(), "emotion_model")
|
17 |
|
18 |
+
# Load pretrained model
|
19 |
classifier = AudioClassifier.from_hparams(
|
20 |
source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP",
|
21 |
+
savedir=model_dir
|
22 |
)
|
23 |
|
24 |
EMOTION_EMOJIS = {
|