File size: 3,072 Bytes
5c97361
feaf7eb
 
 
 
5c97361
 
 
feaf7eb
40f2bca
5c97361
 
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
 
40f2bca
 
 
feaf7eb
40f2bca
feaf7eb
 
40f2bca
feaf7eb
 
40f2bca
 
feaf7eb
40f2bca
feaf7eb
 
40f2bca
feaf7eb
 
40f2bca
 
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
 
feaf7eb
40f2bca
feaf7eb
40f2bca
 
feaf7eb
 
 
40f2bca
 
 
feaf7eb
40f2bca
feaf7eb
 
 
 
 
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
 
 
 
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
 
 
 
40f2bca
feaf7eb
40f2bca
feaf7eb
 
 
40f2bca
 
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
40f2bca
feaf7eb
 
 
 
40f2bca
feaf7eb
 
 
40f2bca
feaf7eb
 
 
 
40f2bca
 
 
feaf7eb
40f2bca
feaf7eb
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
title: Audio Sentiment Analysis
emoji: 🎀
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
license: mit
short_description: Analyze emotions from audio with timeline visualization
app_port: 7860
---

# Audio Sentiment Analysis - Setup Guide

## Quick Start

### 1. Install Dependencies
```bash
uv sync
# or
pip install -r requirements.txt
```

### 2. Configure Environment
```bash
# Copy example config
cp .env.example .env

# Edit .env and set your preferred model
# Default: superb/wav2vec2-base-superb-er
```

### 3. Preload Model (Recommended)
```bash
# Download model before starting the app
uv run python preload_model.py

# This downloads ~100MB-1.3GB depending on model
# Cached in ~/.cache/huggingface/
```

### 4. Start the Application

**Terminal 1 - Flask API:**
```bash
uv run python flask_app.py
```

**Terminal 2 - Streamlit Dashboard:**
```bash
uv run streamlit run streamlit_app.py
```

### 5. Access the App
- **Streamlit UI:** http://localhost:8501
- **Flask API:** http://localhost:5000

---

## Available Models

| Model | Emotions | Size | Speed | Accuracy |
|-------|----------|------|-------|----------|
| `superb/wav2vec2-base-superb-er` | 4 | ~100MB | ⚑⚑⚑ | ⭐⭐ |
| `superb/hubert-large-superb-er` | 4 | ~300MB | ⚑⚑ | ⭐⭐⭐ |
| `ehcalabres/wav2vec2-lg-xlsr` | 7 | ~1.2GB | ⚑ | ⭐⭐⭐⭐ |

**To change model:** Edit `MODEL_NAME` in `.env` file

---

## Configuration Files

- **`.env`** - Your local configuration (not in git)
- **`.env.example`** - Template with all options
- **`config.py`** - Loads environment variables
- **`models_config.py`** - Model-specific settings

---

## Deployment

### Hugging Face Spaces

1. Push to HF Spaces git repository
2. Set environment variables in Space settings
3. Docker will build automatically
4. Model downloads on first run (or add to Dockerfile)

### Adding Model to Docker Image

Edit `Dockerfile` to preload model:
```dockerfile
RUN python preload_model.py
```

This caches the model in the image so deployment is faster.

---

## Troubleshooting

### Model Download Issues
- Check internet connection
- Verify model name in `.env`
- Check disk space (~2GB free recommended)

### "Model not found" errors
- Run `python preload_model.py` first
- Check HuggingFace Hub is accessible

### Slow processing
- Use smaller model (wav2vec2-base)
- Reduce `CHUNK_DURATION` in `.env`
- Consider GPU if available

---

## File Structure

```
.
β”œβ”€β”€ flask_app.py           # Flask API backend
β”œβ”€β”€ streamlit_app.py       # Streamlit dashboard
β”œβ”€β”€ audio_processor.py     # Audio processing logic
β”œβ”€β”€ config.py              # Configuration loader
β”œβ”€β”€ models_config.py       # Model definitions
β”œβ”€β”€ preload_model.py       # Model download script
β”œβ”€β”€ .env                   # Your settings (gitignored)
β”œβ”€β”€ .env.example           # Settings template
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ input/                 # Example audio files
└── uploads/               # Temporary uploads (gitignored)
```