Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
f092eec
1
Parent(s): a3b33c1
Deploy from Achraf-cyber/hackton-locallang@79675fbb76599f38a4324ccb7534683839d2b910
Browse files- Dockerfile +19 -0
- app/deps.py +1 -1
- app/services/asr.py +17 -9
Dockerfile
CHANGED
|
@@ -8,8 +8,27 @@ WORKDIR /app
|
|
| 8 |
COPY requirements.txt .
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
COPY . .
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
EXPOSE 7860
|
| 14 |
|
| 15 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 8 |
COPY requirements.txt .
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
+
# ASR_BACKEND=omnilingual_llm (omniASR-LLM-7B) + TTS_BACKEND_DYU=omnivoice :
|
| 12 |
+
# Linux uniquement (fairseq2n n'a aucun wheel Windows, d'ou l'absence de ces
|
| 13 |
+
# paquets dans requirements.txt, installe aussi en local sous Windows) --
|
| 14 |
+
# safe a installer ici car le Space tourne toujours sous Linux.
|
| 15 |
+
# torch/torchaudio doivent matcher EXACTEMENT le wheel fairseq2 prebuild
|
| 16 |
+
# (voir requirements-omnilingual.txt) ; --no-deps evite que omnilingual-asr
|
| 17 |
+
# ne re-resolve torch en variante CUDA par dessus.
|
| 18 |
+
RUN pip install --no-cache-dir "torch==2.9.1" "torchaudio==2.9.1" \
|
| 19 |
+
--index-url https://download.pytorch.org/whl/cpu \
|
| 20 |
+
&& pip install --no-cache-dir "fairseq2" \
|
| 21 |
+
--extra-index-url https://fair.pkg.atmeta.com/fairseq2/whl/pt2.9.1/cpu \
|
| 22 |
+
--trusted-host fair.pkg.atmeta.com \
|
| 23 |
+
&& pip install --no-cache-dir omnilingual-asr --no-deps \
|
| 24 |
+
&& pip install --no-cache-dir retrying xxhash omnivoice
|
| 25 |
+
|
| 26 |
COPY . .
|
| 27 |
|
| 28 |
+
ENV ASR_BACKEND=omnilingual_llm
|
| 29 |
+
ENV TRANSLATION_BACKEND=afrimt5
|
| 30 |
+
ENV TTS_BACKEND_DYU=omnivoice
|
| 31 |
+
|
| 32 |
EXPOSE 7860
|
| 33 |
|
| 34 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/deps.py
CHANGED
|
@@ -10,7 +10,7 @@ class Settings(BaseSettings):
|
|
| 10 |
ALLOWED_ORIGINS: list[str] = ["*"]
|
| 11 |
|
| 12 |
# Voir app/services/asr.py pour le detail des backends.
|
| 13 |
-
ASR_BACKEND: Literal["local", "hf_api", "omnilingual", "omnilingual_ctc"] = "local"
|
| 14 |
TRANSLATION_BACKEND: Literal["nllb", "afrimt5"] = "nllb"
|
| 15 |
TTS_BACKEND_DYU: Literal["mms", "omnivoice"] = "mms"
|
| 16 |
HF_TOKEN: str | None = None
|
|
|
|
| 10 |
ALLOWED_ORIGINS: list[str] = ["*"]
|
| 11 |
|
| 12 |
# Voir app/services/asr.py pour le detail des backends.
|
| 13 |
+
ASR_BACKEND: Literal["local", "hf_api", "omnilingual", "omnilingual_ctc", "omnilingual_llm"] = "local"
|
| 14 |
TRANSLATION_BACKEND: Literal["nllb", "afrimt5"] = "nllb"
|
| 15 |
TTS_BACKEND_DYU: Literal["mms", "omnivoice"] = "mms"
|
| 16 |
HF_TOKEN: str | None = None
|
app/services/asr.py
CHANGED
|
@@ -10,12 +10,15 @@ Trois backends, choisis par Settings.ASR_BACKEND :
|
|
| 10 |
utilise donc openai/whisper-large-v3 a la place, qui NE supporte PAS
|
| 11 |
officiellement le Dioula ni le Moore (~99 langues entrainees, dyu/mos
|
| 12 |
absentes) : fiable seulement pour lang="fra", best-effort pour dyu/mos.
|
| 13 |
-
- "omnilingual"
|
| 14 |
-
(verifie via lang_ids.py du modele)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
|
| 21 |
import logging
|
|
@@ -41,6 +44,7 @@ MMS_LANG_CODES = {
|
|
| 41 |
|
| 42 |
OMNILINGUAL_MODEL_CARD = "omniASR_CTC_300M_v2"
|
| 43 |
OMNILINGUAL_CTC_MODEL_CARD = "omniASR_CTC_1B"
|
|
|
|
| 44 |
OMNILINGUAL_LANG_CODES = {
|
| 45 |
"dyu": "dyu_Latn",
|
| 46 |
"mos": "mos_Latn",
|
|
@@ -63,10 +67,14 @@ class ASR:
|
|
| 63 |
self._client = InferenceClient(model=HF_API_MODEL_NAME, token=settings.HF_TOKEN)
|
| 64 |
return
|
| 65 |
|
| 66 |
-
if self.backend in ("omnilingual", "omnilingual_ctc"):
|
| 67 |
from omnilingual_asr.models.inference.pipeline import ASRInferencePipeline
|
| 68 |
|
| 69 |
-
model_card =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
self._omni_pipeline = ASRInferencePipeline(model_card=model_card)
|
| 71 |
return
|
| 72 |
|
|
@@ -133,7 +141,7 @@ class ASR:
|
|
| 133 |
if self.backend == "hf_api":
|
| 134 |
return self._transcribe_hf_api(audio_path, lang)
|
| 135 |
|
| 136 |
-
if self.backend in ("omnilingual", "omnilingual_ctc"):
|
| 137 |
return self._transcribe_omnilingual(audio_path, lang)
|
| 138 |
|
| 139 |
self._set_lang(lang)
|
|
|
|
| 10 |
utilise donc openai/whisper-large-v3 a la place, qui NE supporte PAS
|
| 11 |
officiellement le Dioula ni le Moore (~99 langues entrainees, dyu/mos
|
| 12 |
absentes) : fiable seulement pour lang="fra", best-effort pour dyu/mos.
|
| 13 |
+
- "omnilingual" / "omnilingual_ctc" / "omnilingual_llm" : Meta Omnilingual ASR
|
| 14 |
+
(2025), couvre nativement dyu/mos (verifie via lang_ids.py du modele) --
|
| 15 |
+
respectivement omniASR_CTC_300M_v2, omniASR_CTC_1B, omniASR_LLM_7B (le plus
|
| 16 |
+
gros et le plus precis, utilise en prod -- voir model-service/Dockerfile).
|
| 17 |
+
Necessite le paquet omnilingual-asr (fairseq2 + fairseq2n), qui n'a AUCUN
|
| 18 |
+
wheel Windows -- fonctionne uniquement sous Linux/WSL. L'import est fait en
|
| 19 |
+
lazy pour ne pas casser les backends "local"/"hf_api" sur une machine
|
| 20 |
+
Windows sans ce paquet.
|
| 21 |
+
Le contrat de transcribe(audio_path, lang) est identique dans tous les cas.
|
| 22 |
"""
|
| 23 |
|
| 24 |
import logging
|
|
|
|
| 44 |
|
| 45 |
OMNILINGUAL_MODEL_CARD = "omniASR_CTC_300M_v2"
|
| 46 |
OMNILINGUAL_CTC_MODEL_CARD = "omniASR_CTC_1B"
|
| 47 |
+
OMNILINGUAL_LLM_MODEL_CARD = "omniASR_LLM_7B"
|
| 48 |
OMNILINGUAL_LANG_CODES = {
|
| 49 |
"dyu": "dyu_Latn",
|
| 50 |
"mos": "mos_Latn",
|
|
|
|
| 67 |
self._client = InferenceClient(model=HF_API_MODEL_NAME, token=settings.HF_TOKEN)
|
| 68 |
return
|
| 69 |
|
| 70 |
+
if self.backend in ("omnilingual", "omnilingual_ctc", "omnilingual_llm"):
|
| 71 |
from omnilingual_asr.models.inference.pipeline import ASRInferencePipeline
|
| 72 |
|
| 73 |
+
model_card = {
|
| 74 |
+
"omnilingual": OMNILINGUAL_MODEL_CARD,
|
| 75 |
+
"omnilingual_ctc": OMNILINGUAL_CTC_MODEL_CARD,
|
| 76 |
+
"omnilingual_llm": OMNILINGUAL_LLM_MODEL_CARD,
|
| 77 |
+
}[self.backend]
|
| 78 |
self._omni_pipeline = ASRInferencePipeline(model_card=model_card)
|
| 79 |
return
|
| 80 |
|
|
|
|
| 141 |
if self.backend == "hf_api":
|
| 142 |
return self._transcribe_hf_api(audio_path, lang)
|
| 143 |
|
| 144 |
+
if self.backend in ("omnilingual", "omnilingual_ctc", "omnilingual_llm"):
|
| 145 |
return self._transcribe_omnilingual(audio_path, lang)
|
| 146 |
|
| 147 |
self._set_lang(lang)
|