ibrahimm7004 commited on
Commit
aaa42b0
·
1 Parent(s): ace74dd

Switch to handler.py deployment

Browse files
Files changed (5) hide show
  1. Dockerfile +0 -28
  2. app.py +0 -24
  3. handler.py +27 -0
  4. huggingface.yaml +0 -15
  5. requirements.txt +2 -4
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
20
-
21
- # Copy app code
22
- COPY app.py .
23
-
24
- # Expose port
25
- EXPOSE 7860
26
-
27
- # Start FastAPI server
28
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py DELETED
@@ -1,24 +0,0 @@
1
- from fastapi import FastAPI, UploadFile, Form
2
- from fastapi.responses import FileResponse
3
- import uuid, os, soundfile as sf
4
- from TTS.api import TTS
5
-
6
- app = FastAPI()
7
-
8
- # Load XTTS model (multi-lingual, multi-speaker)
9
- # This will be slow on cold start but stays cached in memory
10
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")
11
-
12
- @app.post("/generate")
13
- async def generate(text: str = Form(...), speaker_wav: UploadFile = None):
14
- output_path = f"/tmp/{uuid.uuid4().hex}.wav"
15
-
16
- if speaker_wav:
17
- wav_path = f"/tmp/{speaker_wav.filename}"
18
- with open(wav_path, "wb") as f:
19
- f.write(await speaker_wav.read())
20
- tts.tts_to_file(text=text, speaker_wav=wav_path, file_path=output_path)
21
- else:
22
- tts.tts_to_file(text=text, speaker="random", file_path=output_path)
23
-
24
- return FileResponse(output_path, media_type="audio/wav")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
handler.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ from TTS.api import TTS
3
+ import uuid
4
+ import os
5
+
6
+
7
+ class EndpointHandler:
8
+ def __init__(self, path=""):
9
+ # Load XTTS model
10
+ self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
11
+
12
+ def __call__(self, data: Dict[str, str]) -> Dict[str, str]:
13
+ # Input text
14
+ text = data.get("text", "")
15
+ speaker_wav = data.get("speaker_wav", None)
16
+
17
+ # Output path
18
+ output_path = f"/tmp/{uuid.uuid4().hex}.wav"
19
+
20
+ if speaker_wav:
21
+ self.tts.tts_to_file(
22
+ text=text, speaker_wav=speaker_wav, file_path=output_path)
23
+ else:
24
+ self.tts.tts_to_file(
25
+ text=text, speaker="random", file_path=output_path)
26
+
27
+ return {"audio_file": output_path}
huggingface.yaml DELETED
@@ -1,15 +0,0 @@
1
- # Hugging Face Inference Endpoint config
2
- build:
3
- dockerfile: Dockerfile
4
-
5
- resources:
6
- # Use CPU instance for free/low-cost deployment
7
- cpu: "2"
8
- memory: "8Gi"
9
-
10
- scaling:
11
- # Scale-to-zero when idle → no charges while unused
12
- min_replicas: 0
13
- max_replicas: 1
14
-
15
- entrypoint: uvicorn app:app --host 0.0.0.0 --port 7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,8 +1,6 @@
1
- fastapi==0.110.0
2
- uvicorn==0.29.0
3
- soundfile==0.12.1
4
- numpy==1.26.4
5
  torch==2.1.0
6
  torchaudio==2.1.0
7
  transformers==4.38.1
8
  TTS==0.21.1
 
 
 
 
 
 
 
1
  torch==2.1.0
2
  torchaudio==2.1.0
3
  transformers==4.38.1
4
  TTS==0.21.1
5
+ soundfile==0.12.1
6
+ numpy==1.26.4