Anicet commited on
Commit ·
cc36729
1
Parent(s): a6299ef
update: minors corrections
Browse files- .dockerignore +1 -0
- Dockerfile +7 -1
- functions/translation.py +8 -6
- language/dioula/dyu_stt.py +5 -3
- language/moore/mos_stt.py +4 -2
- main.py +2 -0
.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv
|
Dockerfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
-
# FROM
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
|
@@ -7,8 +7,14 @@ RUN apt-get update && apt-get install -y git ffmpeg
|
|
| 7 |
|
| 8 |
COPY . .
|
| 9 |
|
|
|
|
|
|
|
| 10 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 11 |
|
| 12 |
# EXPOSE 8000
|
| 13 |
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
| 14 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
+
# FROM nvidia/cuda:12.1.1-runtime-ubuntu22.04
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
|
|
|
|
| 7 |
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
+
# RUN pip install --upgrade pip setuptools wheel
|
| 11 |
+
|
| 12 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
|
| 14 |
# EXPOSE 8000
|
| 15 |
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
| 16 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 17 |
+
|
| 18 |
+
# docker buildx build --platform linux/amd64 --no-cache -t ai-api .
|
| 19 |
+
# docker tag ai-api kora3/ai-api:latest
|
| 20 |
+
# docker push kora3/ai-api:latest
|
functions/translation.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 2 |
import torch
|
| 3 |
|
| 4 |
-
MODEL_NAME = "facebook/nllb-200-distilled-600M"
|
| 5 |
-
|
| 6 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 7 |
|
|
|
|
|
|
|
| 8 |
model.eval()
|
| 9 |
|
| 10 |
|
| 11 |
def translateText(text: str, sourceLang: str, targetLang: str) -> str:
|
| 12 |
tokenizer.src_lang = sourceLang
|
| 13 |
-
inputs = tokenizer(text, return_tensors="pt")
|
| 14 |
|
| 15 |
with torch.no_grad():
|
| 16 |
tokens = model.generate(
|
| 17 |
**inputs,
|
| 18 |
forced_bos_token_id=tokenizer.convert_tokens_to_ids(targetLang),
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
translatedText = tokenizer.batch_decode(tokens, skip_special_tokens=True)[0]
|
|
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 2 |
import torch
|
| 3 |
|
| 4 |
+
MODEL_NAME = "facebook/nllb-200-distilled-600M" # facebook/nllb-200-3.3B
|
| 5 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 6 |
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME).to(device)
|
| 9 |
model.eval()
|
| 10 |
|
| 11 |
|
| 12 |
def translateText(text: str, sourceLang: str, targetLang: str) -> str:
|
| 13 |
tokenizer.src_lang = sourceLang
|
| 14 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 15 |
|
| 16 |
with torch.no_grad():
|
| 17 |
tokens = model.generate(
|
| 18 |
**inputs,
|
| 19 |
forced_bos_token_id=tokenizer.convert_tokens_to_ids(targetLang),
|
| 20 |
+
max_new_tokens=512,
|
| 21 |
+
num_beams=4,
|
| 22 |
+
early_stopping=True,
|
| 23 |
)
|
| 24 |
|
| 25 |
translatedText = tokenizer.batch_decode(tokens, skip_special_tokens=True)[0]
|
language/dioula/dyu_stt.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
-
import base64, tempfile, os
|
| 2 |
from transformers import pipeline
|
| 3 |
from functions.utils import getAudioDuration
|
| 4 |
|
| 5 |
MODEL_NAME = "facebook/mms-1b-all"
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def dioulaSTT(audioBase64: str) -> dict:
|
|
@@ -20,4 +22,4 @@ def dioulaSTT(audioBase64: str) -> dict:
|
|
| 20 |
finally:
|
| 21 |
os.remove(tempAudioPath)
|
| 22 |
|
| 23 |
-
return {'text': text, 'language': '
|
|
|
|
| 1 |
+
import base64, tempfile, os, torch
|
| 2 |
from transformers import pipeline
|
| 3 |
from functions.utils import getAudioDuration
|
| 4 |
|
| 5 |
MODEL_NAME = "facebook/mms-1b-all"
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
pipe = pipeline("automatic-speech-recognition", model=MODEL_NAME, model_kwargs={"target_lang": "dyu"}, device=device)
|
| 9 |
|
| 10 |
|
| 11 |
def dioulaSTT(audioBase64: str) -> dict:
|
|
|
|
| 22 |
finally:
|
| 23 |
os.remove(tempAudioPath)
|
| 24 |
|
| 25 |
+
return {'text': text, 'language': 'dyu', 'duration': duration}
|
language/moore/mos_stt.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
-
import base64, tempfile, os
|
| 2 |
from transformers import pipeline
|
| 3 |
from functions.utils import getAudioDuration
|
| 4 |
# from huggingface_hub import login
|
| 5 |
|
| 6 |
MODEL_NAME = "facebook/mms-1b-all"
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
# login(token=os.environ["HF_TOKEN"])
|
| 9 |
# MODEL_NAME = "burkimbia/BIA-WHISPER-LARGE-SACHI_V3"
|
| 10 |
# pipe = pipeline("automatic-speech-recognition", model=MODEL_NAME)
|
|
|
|
| 1 |
+
import base64, tempfile, os, torch
|
| 2 |
from transformers import pipeline
|
| 3 |
from functions.utils import getAudioDuration
|
| 4 |
# from huggingface_hub import login
|
| 5 |
|
| 6 |
MODEL_NAME = "facebook/mms-1b-all"
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
|
| 9 |
+
pipe = pipeline("automatic-speech-recognition", model=MODEL_NAME, model_kwargs={"target_lang": "mos"}, device=device)
|
| 10 |
# login(token=os.environ["HF_TOKEN"])
|
| 11 |
# MODEL_NAME = "burkimbia/BIA-WHISPER-LARGE-SACHI_V3"
|
| 12 |
# pipe = pipeline("automatic-speech-recognition", model=MODEL_NAME)
|
main.py
CHANGED
|
@@ -2,8 +2,10 @@ from fastapi import FastAPI, Request, HTTPException
|
|
| 2 |
from functions.translation import translateText
|
| 3 |
from functions.speech_to_text import speechToText
|
| 4 |
from functions.text_to_speech import textToSpeech
|
|
|
|
| 5 |
from language.moore.mos_stt import mooreSTT
|
| 6 |
from language.moore.mos_tts import mooreTTS
|
|
|
|
| 7 |
from language.dioula.dyu_stt import dioulaSTT
|
| 8 |
from language.dioula.dyu_tts import dioulaTTS
|
| 9 |
|
|
|
|
| 2 |
from functions.translation import translateText
|
| 3 |
from functions.speech_to_text import speechToText
|
| 4 |
from functions.text_to_speech import textToSpeech
|
| 5 |
+
|
| 6 |
from language.moore.mos_stt import mooreSTT
|
| 7 |
from language.moore.mos_tts import mooreTTS
|
| 8 |
+
|
| 9 |
from language.dioula.dyu_stt import dioulaSTT
|
| 10 |
from language.dioula.dyu_tts import dioulaTTS
|
| 11 |
|