Spaces:
Runtime error
Runtime error
Commit
·
50e7df1
1
Parent(s):
791a2a5
Primer commit - Implementación App
Browse files- Dockerfile +11 -0
- app.py +34 -0
- requirements.txt +7 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./ /code/
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, send_file, request
|
2 |
+
from flask_cors import CORS
|
3 |
+
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
|
4 |
+
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
|
5 |
+
import IPython.display as ipd
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
CORS(app)
|
9 |
+
|
10 |
+
models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
|
11 |
+
"facebook/tts_transformer-es-css10",
|
12 |
+
arg_overrides={"vocoder": "hifigan", "fp16": False}
|
13 |
+
)
|
14 |
+
model = models[0]
|
15 |
+
TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
|
16 |
+
generator = task.build_generator([model], cfg)
|
17 |
+
|
18 |
+
@app.route("/")
|
19 |
+
def get_audio():
|
20 |
+
user = request.args.get('name')
|
21 |
+
text = f"Hola {user}, si estás leyendo este mail es porque desde buenosaires consideramos que eres una de esas personas visionarias, capaces de mirar más allá, por eso queremos compartir contigo un hallazgo que puede cambiar el futuro de las enfermedades degenerativas."
|
22 |
+
|
23 |
+
sample = TTSHubInterface.get_model_input(task, text)
|
24 |
+
wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
|
25 |
+
print(f"Duration: {len(wav) / rate:.2f} seconds")
|
26 |
+
print(f"Text: {text}")
|
27 |
+
sound = ipd.Audio(wav, rate=rate)
|
28 |
+
with open("../../audio_file.wav", "wb") as file:
|
29 |
+
file.write(sound.data)
|
30 |
+
|
31 |
+
return send_file("../../audio_file.wav", mimetype="audio/wav")
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
app.run(port=7860, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fairseq==0.12.2
|
2 |
+
Flask==2.2.3
|
3 |
+
Flask-Cors==3.0.10
|
4 |
+
huggingface-hub==0.13.4
|
5 |
+
sentencepiece==0.1.98
|
6 |
+
ipython==8.12.0
|
7 |
+
tensorboardX==2.6
|