ibrahimm7004 commited on
Commit
3c9ee02
·
1 Parent(s): 49ee1a8

Switch to handler.py deployment

Browse files
Files changed (4) hide show
  1. Dockerfile +0 -28
  2. handler.py +36 -0
  3. huggingface.yaml +3 -4
  4. requirements.txt +0 -2
Dockerfile DELETED
@@ -1,28 +0,0 @@
1
- FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime
2
-
3
- # Prevent interactive tzdata prompts and accept Coqui TOS
4
- ENV DEBIAN_FRONTEND=noninteractive
5
- ENV TZ=Etc/UTC
6
- ENV COQUI_TOS_AGREED=1
7
-
8
- # Install system dependencies
9
- RUN apt-get update && \
10
- apt-get install -y git ffmpeg libsndfile1 tzdata && \
11
- rm -rf /var/lib/apt/lists/*
12
-
13
- # Create working directory
14
- WORKDIR /app
15
-
16
- # Install Python dependencies
17
- COPY requirements.txt .
18
-
19
- RUN pip install --ignore-installed --no-cache-dir -r requirements.txt -f https://download.pytorch.org/whl/cpu/torch_stable.html
20
-
21
- # Copy app code
22
- COPY app.py .
23
-
24
- # Expose port
25
- EXPOSE 7860
26
-
27
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
28
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
handler.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any
2
+ import torch
3
+ from TTS.api import TTS
4
+
5
+
6
+ class EndpointHandler:
7
+ def __init__(self, path=""):
8
+ # Load Coqui XTTS model (weights are downloaded automatically)
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ self.tts = TTS(
11
+ "tts_models/multilingual/multi-dataset/xtts_v2").to(device)
12
+ self.device = device
13
+
14
+ def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
15
+ """
16
+ Expected input:
17
+ {
18
+ "text": "Hello world",
19
+ "speaker_wav": "path/to/voice.wav" (optional, for cloning),
20
+ "language": "en"
21
+ }
22
+ """
23
+ text = data.get("text", "")
24
+ speaker_wav = data.get("speaker_wav", None)
25
+ language = data.get("language", "en")
26
+
27
+ # Generate speech
28
+ output_path = "output.wav"
29
+ self.tts.tts_to_file(
30
+ text=text,
31
+ speaker_wav=speaker_wav,
32
+ language=language,
33
+ file_path=output_path
34
+ )
35
+
36
+ return {"audio": output_path}
huggingface.yaml CHANGED
@@ -1,6 +1,4 @@
1
- build:
2
- dockerfile: Dockerfile
3
-
4
  resources:
5
  cpu: "2"
6
  memory: "8Gi"
@@ -9,4 +7,5 @@ scaling:
9
  min_replicas: 0
10
  max_replicas: 1
11
 
12
- entrypoint: uvicorn app:app --host 0.0.0.0 --port 7860
 
 
1
+ # huggingface.yaml
 
 
2
  resources:
3
  cpu: "2"
4
  memory: "8Gi"
 
7
  min_replicas: 0
8
  max_replicas: 1
9
 
10
+ # Tell HF to use handler.py
11
+ entrypoint: handler.py
requirements.txt CHANGED
@@ -2,7 +2,5 @@ fastapi==0.110.0
2
  uvicorn==0.29.0
3
  soundfile==0.12.1
4
  numpy==1.26.4
5
- torch==2.1.0+cpu
6
- torchaudio==2.1.0+cpu
7
  transformers==4.38.1
8
  TTS==0.21.1
 
2
  uvicorn==0.29.0
3
  soundfile==0.12.1
4
  numpy==1.26.4
 
 
5
  transformers==4.38.1
6
  TTS==0.21.1