Spaces:
Sleeping
Sleeping
Refactor Dockerfile and Streamlit app to improve dependency installation and update accent detection model
Browse files- Dockerfile +10 -1
- src/streamlit_app.py +4 -5
Dockerfile
CHANGED
@@ -2,6 +2,7 @@ FROM python:3.9-slim
|
|
2 |
|
3 |
WORKDIR /app
|
4 |
|
|
|
5 |
RUN apt-get update && apt-get install -y \
|
6 |
build-essential \
|
7 |
curl \
|
@@ -11,13 +12,21 @@ RUN apt-get update && apt-get install -y \
|
|
11 |
libsndfile1 \
|
12 |
&& rm -rf /var/lib/apt/lists/*
|
13 |
|
|
|
14 |
COPY requirements.txt ./
|
|
|
|
|
|
|
15 |
COPY src/ ./src/
|
16 |
|
17 |
-
|
|
|
18 |
|
|
|
19 |
EXPOSE 8501
|
20 |
|
|
|
21 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
22 |
|
|
|
23 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
2 |
|
3 |
WORKDIR /app
|
4 |
|
5 |
+
# Install system dependencies including ffmpeg for audio processing
|
6 |
RUN apt-get update && apt-get install -y \
|
7 |
build-essential \
|
8 |
curl \
|
|
|
12 |
libsndfile1 \
|
13 |
&& rm -rf /var/lib/apt/lists/*
|
14 |
|
15 |
+
# Copy requirements and install Python dependencies
|
16 |
COPY requirements.txt ./
|
17 |
+
RUN pip3 install --no-cache-dir -r requirements.txt
|
18 |
+
|
19 |
+
# Copy source code
|
20 |
COPY src/ ./src/
|
21 |
|
22 |
+
# Create directory for temporary model storage
|
23 |
+
RUN mkdir -p /app/tmp_model
|
24 |
|
25 |
+
# Expose the port Streamlit will run on
|
26 |
EXPOSE 8501
|
27 |
|
28 |
+
# Health check to ensure the service is running
|
29 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
30 |
|
31 |
+
# Run the Streamlit app
|
32 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
src/streamlit_app.py
CHANGED
@@ -5,7 +5,7 @@ import subprocess
|
|
5 |
import librosa
|
6 |
import numpy as np
|
7 |
import torch
|
8 |
-
from speechbrain.
|
9 |
from transformers import AutoProcessor, AutoModelForAudioClassification
|
10 |
from dotenv import load_dotenv
|
11 |
import matplotlib.pyplot as plt
|
@@ -76,7 +76,7 @@ def extract_audio(video_path="video.mp4", audio_path="audio.wav"):
|
|
76 |
class AccentDetector:
|
77 |
def __init__(self):
|
78 |
# Initialize the language identification model
|
79 |
-
self.lang_id =
|
80 |
source="speechbrain/lang-id-commonlanguage_ecapa",
|
81 |
savedir="tmp_model"
|
82 |
)
|
@@ -96,9 +96,8 @@ class AccentDetector:
|
|
96 |
"""
|
97 |
Determine if the speech is English and return confidence score
|
98 |
"""
|
99 |
-
|
100 |
-
|
101 |
-
score = float(prediction[0][0])
|
102 |
|
103 |
# Check if language is English (slightly fuzzy match)
|
104 |
is_english = "eng" in lang.lower() or "en-" in lang.lower() or lang.lower() == "en"
|
|
|
5 |
import librosa
|
6 |
import numpy as np
|
7 |
import torch
|
8 |
+
from speechbrain.inference.classifiers import EncoderClassifier
|
9 |
from transformers import AutoProcessor, AutoModelForAudioClassification
|
10 |
from dotenv import load_dotenv
|
11 |
import matplotlib.pyplot as plt
|
|
|
76 |
class AccentDetector:
|
77 |
def __init__(self):
|
78 |
# Initialize the language identification model
|
79 |
+
self.lang_id = EncoderClassifier.from_hparams(
|
80 |
source="speechbrain/lang-id-commonlanguage_ecapa",
|
81 |
savedir="tmp_model"
|
82 |
)
|
|
|
96 |
"""
|
97 |
Determine if the speech is English and return confidence score
|
98 |
"""
|
99 |
+
out_prob, score, index, lang = self.lang_id.classify_file(audio_path)
|
100 |
+
score = float(score)
|
|
|
101 |
|
102 |
# Check if language is English (slightly fuzzy match)
|
103 |
is_english = "eng" in lang.lower() or "en-" in lang.lower() or lang.lower() == "en"
|