Sofia Casadei commited on
Commit
91537f8
·
1 Parent(s): 720ee5c
Files changed (5) hide show
  1. Dockerfile +42 -16
  2. Dockerfile.pip +27 -0
  3. Dockerfile.uv +0 -49
  4. main.py +16 -15
  5. requirements.txt +6 -6
Dockerfile CHANGED
@@ -1,27 +1,53 @@
1
- FROM python:3.11
 
2
 
3
- # Set the working directory to /code
4
- WORKDIR /code
5
 
6
- # Copy the current directory contents into the container at /code
7
- COPY ./requirements.txt /code/requirements.txt
8
 
9
- # Install requirements.txt
10
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
 
11
 
12
- # Set up a new user named "user" with user ID 1000
13
- RUN useradd -m -u 1000 user
 
14
 
15
- # Switch to the "user" user
 
 
 
 
16
  USER user
17
- # Set home to the user's home directory
 
 
18
  ENV HOME=/home/user \
19
- PATH=/home/user/.local/bin:$PATH
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- # Set the working directory to the user's home directory
22
- WORKDIR $HOME/app
23
 
24
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
25
- COPY --chown=user . $HOME/app
 
26
 
 
27
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Stage 1: Get uv installer
2
+ FROM ghcr.io/astral-sh/uv:0.2.12 as uv
3
 
4
+ # Stage 2: Main application image
5
+ FROM python:3.11.9-slim-bookworm
6
 
7
+ # Copy uv from first stage
8
+ COPY --from=uv /uv /uv
9
 
10
+ # Create virtual environment with uv
11
+ RUN --mount=type=cache,target=/root/.cache/uv \
12
+ /uv venv /opt/venv
13
 
14
+ # Set environment variables
15
+ ENV VIRTUAL_ENV=/opt/venv \
16
+ PATH="/opt/venv/bin:$PATH"
17
 
18
+ # Create user and set permissions (required for HF Spaces)
19
+ RUN useradd -m -u 1000 user && \
20
+ chown -R user /opt/venv
21
+
22
+ # Switch to user context
23
  USER user
24
+ WORKDIR /app
25
+
26
+ # Set home to user's home directory
27
  ENV HOME=/home/user \
28
+ PATH=/home/user/.local/bin:$PATH \
29
+ HF_HOME=/home/user/.cache/huggingface \
30
+ UV_CACHE_DIR=/app/.uv-cache
31
+
32
+ # Create cache directory with proper permissions
33
+ RUN mkdir -p $UV_CACHE_DIR && chown -R user:user $UV_CACHE_DIR
34
+
35
+ # Copy requirements first for caching
36
+ COPY --chown=user requirements.txt .
37
+
38
+ # Install Python packages with uv caching
39
+ RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
40
+ /uv pip install -r requirements.txt
41
+
42
+ # Copy application code
43
+ COPY --chown=user . .
44
 
45
+ # Expose FastRTC port (matches HF Spaces default)
46
+ EXPOSE 7860
47
 
48
+ # Check gpu and cuda
49
+ RUN python -c "import torch; print(torch.cuda.is_available())"
50
+ RUN nvidia-smi
51
 
52
+ # Start the application using uvicorn (FastAPI)
53
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
Dockerfile.pip ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.9
2
+
3
+ # Set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ # Copy the current directory contents into the container at /code
7
+ COPY ./requirements.txt /code/requirements.txt
8
+
9
+ # Install requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ # Set up a new user named "user" with user ID 1000
13
+ RUN useradd -m -u 1000 user
14
+
15
+ # Switch to the "user" user
16
+ USER user
17
+ # Set home to the user's home directory
18
+ ENV HOME=/home/user \
19
+ PATH=/home/user/.local/bin:$PATH
20
+
21
+ # Set the working directory to the user's home directory
22
+ WORKDIR $HOME/app
23
+
24
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
25
+ COPY --chown=user . $HOME/app
26
+
27
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
Dockerfile.uv DELETED
@@ -1,49 +0,0 @@
1
- # Stage 1: Get uv installer
2
- FROM ghcr.io/astral-sh/uv:0.2.12 as uv
3
-
4
- # Stage 2: Main application image
5
- FROM python:3.10.12-slim-bookworm
6
-
7
- # Copy uv from first stage
8
- COPY --from=uv /uv /uv
9
-
10
- # Create virtual environment with uv
11
- RUN --mount=type=cache,target=/root/.cache/uv \
12
- /uv venv /opt/venv
13
-
14
- # Set environment variables
15
- ENV VIRTUAL_ENV=/opt/venv \
16
- PATH="/opt/venv/bin:$PATH"
17
-
18
- # Create user and set permissions (required for HF Spaces)
19
- RUN useradd -m -u 1000 user && \
20
- chown -R user /opt/venv
21
-
22
- # Switch to user context
23
- USER user
24
- WORKDIR /app
25
-
26
- # Set home to user's home directory
27
- ENV HOME=/home/user \
28
- PATH=/home/user/.local/bin:$PATH \
29
- HF_HOME=/home/user/.cache/huggingface \
30
- UV_CACHE_DIR=/app/.uv-cache
31
-
32
- # Create cache directory with proper permissions
33
- RUN mkdir -p $UV_CACHE_DIR && chown -R user:user $UV_CACHE_DIR
34
-
35
- # Copy requirements first for caching
36
- COPY --chown=user requirements.txt .
37
-
38
- # Install Python packages with uv caching
39
- RUN --mount=type=cache,target=$UV_CACHE_DIR,uid=1000,gid=1000 \
40
- /uv pip install -r requirements.txt
41
-
42
- # Copy application code
43
- COPY --chown=user . .
44
-
45
- # Expose FastRTC port (matches HF Spaces default)
46
- EXPOSE 7860
47
-
48
- # Start the application using uvicorn (FastAPI)
49
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py CHANGED
@@ -99,20 +99,20 @@ stream = Stream(
99
  # If, after the user started speaking, there is a chunk with less than speech_threshold seconds of speech, the user stopped speaking. (default 0.1)
100
  speech_threshold=0.1,
101
  ),
102
- model_options=SileroVadOptions(
103
- # Threshold for what is considered speech (default 0.5)
104
- threshold=0.5,
105
- # Final speech chunks shorter min_speech_duration_ms are thrown out (default 250)
106
- min_speech_duration_ms=250,
107
- # Max duration of speech chunks, longer will be split (default float('inf'))
108
- max_speech_duration_s=30,
109
- # Wait for ms at the end of each speech chunk before separating it (default 2000)
110
- min_silence_duration_ms=2000,
111
- # Chunk size for VAD model. Can be 512, 1024, 1536 for 16k s.r. (default 1024)
112
- window_size_samples=1024,
113
- # Final speech chunks are padded by speech_pad_ms each side (default 400)
114
- speech_pad_ms=400,
115
- ),
116
  ),
117
  # send-receive: bidirectional streaming (default)
118
  # send: client to server only
@@ -123,7 +123,8 @@ stream = Stream(
123
  gr.Textbox(label="Transcript"),
124
  ],
125
  additional_outputs_handler=lambda current, new: current + " " + new,
126
- rtc_configuration=get_rtc_credentials(provider="hf") if os.getenv("APP_MODE") == "deployed" else None
 
127
  )
128
 
129
  app = FastAPI()
 
99
  # If, after the user started speaking, there is a chunk with less than speech_threshold seconds of speech, the user stopped speaking. (default 0.1)
100
  speech_threshold=0.1,
101
  ),
102
+ #model_options=SileroVadOptions(
103
+ # # Threshold for what is considered speech (default 0.5)
104
+ # threshold=0.5,
105
+ # Final speech chunks shorter min_speech_duration_ms are thrown out (default 250)
106
+ # min_speech_duration_ms=250,
107
+ # Max duration of speech chunks, longer will be split (default float('inf'))
108
+ # max_speech_duration_s=30,
109
+ # Wait for ms at the end of each speech chunk before separating it (default 2000)
110
+ # min_silence_duration_ms=2000,
111
+ # Chunk size for VAD model. Can be 512, 1024, 1536 for 16k s.r. (default 1024)
112
+ # window_size_samples=1024,
113
+ # Final speech chunks are padded by speech_pad_ms each side (default 400)
114
+ # speech_pad_ms=400,
115
+ #),
116
  ),
117
  # send-receive: bidirectional streaming (default)
118
  # send: client to server only
 
123
  gr.Textbox(label="Transcript"),
124
  ],
125
  additional_outputs_handler=lambda current, new: current + " " + new,
126
+ rtc_configuration=get_rtc_credentials(provider="hf") if os.getenv("APP_MODE") == "deployed" else None,
127
+ concurrency_limit=6
128
  )
129
 
130
  app = FastAPI()
requirements.txt CHANGED
@@ -1,9 +1,9 @@
1
- accelerate==1.4.0
2
- fastrtc==0.0.10
3
  fastrtc[vad]
4
- python-dotenv==1.0.1
5
- transformers==4.49.0
6
- torch==2.6.0
7
- torchaudio==2.6.0
8
  fastapi
9
  uvicorn[standard]
 
1
+ accelerate
2
+ fastrtc
3
  fastrtc[vad]
4
+ python-dotenv
5
+ transformers
6
+ torch
7
+ torchaudio
8
  fastapi
9
  uvicorn[standard]