Spaces:
Running
on
Zero
Running
on
Zero
Delete app.py
Browse files
app.py
DELETED
@@ -1,132 +0,0 @@
|
|
1 |
-
import spaces
|
2 |
-
import torch
|
3 |
-
import scipy
|
4 |
-
import torchaudio
|
5 |
-
|
6 |
-
import gradio as gr
|
7 |
-
from transformers import pipeline, set_seed
|
8 |
-
from huggingface_hub import login
|
9 |
-
|
10 |
-
import os
|
11 |
-
from languages import get_language_names
|
12 |
-
from goai_helpers import goai_traduction, goai_stt, goai_stt2, goai_tts, goai_tts2
|
13 |
-
|
14 |
-
|
15 |
-
auth_token = os.getenv('HF_SPACE_TOKEN')
|
16 |
-
login(token=auth_token)
|
17 |
-
|
18 |
-
|
19 |
-
# list all files in the ./audios directory for the dropdown
|
20 |
-
AUDIO_FILES = [f for f in os.listdir('./exples_voix') if os.path.isfile(os.path.join('./exples_voix', f))]
|
21 |
-
|
22 |
-
DESCRIPTION = """<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
|
23 |
-
<div style="flex: 1; min-width: 250px;">
|
24 |
-
Ce modèle de traduction vers la <b>langue Mooré</b> a été développé from scratch par <b>GO AI CORP</b> et la version disponible en test est celle à 700 millions de paramètres.
|
25 |
-
<br><br>
|
26 |
-
Pour les détails techniques sur l'architecture du modèle, prendre attache avec nous via WhatsApp au <b>+226 66 62 83 03</b>.
|
27 |
-
</div>
|
28 |
-
<div style="flex-shrink: 0; min-width: 150px; text-align: center;">
|
29 |
-
<img src="https://github.com/ANYANTUDRE/Stage-IA-Selever-GO-AI-Corp/blob/main/img/goaicorp-logo2.jpg?raw=true" width="300px" style="max-width: 100%; height: auto;">
|
30 |
-
</div>
|
31 |
-
</div>
|
32 |
-
"""
|
33 |
-
# Whisper's full language ID mapping
|
34 |
-
LANG_TO_ID = {
|
35 |
-
"en": 0, "zh": 1, "de": 2, "es": 3, "ru": 4, "ko": 5, "fr": 6, "ja": 7,
|
36 |
-
"pt": 8, "tr": 9, "pl": 10, "ca": 11, "nl": 12, "ar": 13, "sv": 14,
|
37 |
-
"it": 15, "id": 16, "hi": 17, "fi": 18, "vi": 19, "he": 20, "uk": 21,
|
38 |
-
"el": 22, "ms": 23, "cs": 24, "ro": 25, "da": 26, "hu": 27, "ta": 28,
|
39 |
-
"no": 29, "th": 30, "ur": 31, "hr": 32, "bg": 33, "lt": 34, "la": 35,
|
40 |
-
"mi": 36, "ml": 37, "cy": 38, "sk": 39, "te": 40, "fa": 41, "lv": 42,
|
41 |
-
"bn": 43, "sr": 44, "az": 45, "sl": 46, "kn": 47, "et": 48, "mk": 49,
|
42 |
-
"br": 50, "eu": 51, "is": 52, "hy": 53, "ne": 54, "mn": 55, "bs": 56,
|
43 |
-
"kk": 57, "sq": 58, "sw": 59, "gl": 60, "mr": 61, "pa": 62, "si": 63,
|
44 |
-
"km": 64, "sn": 65, "yo": 66, "so": 67, "af": 68, "oc": 69, "ka": 70,
|
45 |
-
"be": 71, "tg": 72, "sd": 73, "gu": 74, "am": 75, "yi": 76, "lo": 77,
|
46 |
-
"uz": 78, "fo": 79, "ht": 80, "ps": 81, "tk": 82, "nn": 83, "mt": 84,
|
47 |
-
"sa": 85, "lb": 86, "my": 87, "bo": 88, "tl": 89, "mg": 90, "as": 91,
|
48 |
-
"tt": 92, "haw": 93, "ln": 94, "ha": 95, "ba": 96, "jw": 97, "su": 98
|
49 |
-
}
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
demo = gr.Blocks(theme=gr.themes.Ocean())
|
54 |
-
|
55 |
-
goai_stt = gr.Interface(
|
56 |
-
fn=goai_stt2.transcribe,
|
57 |
-
inputs=[
|
58 |
-
gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
59 |
-
gr.Dropdown(
|
60 |
-
choices=[
|
61 |
-
"ArissBandoss/whisper-small-mos",
|
62 |
-
"openai/whisper-large-v3-turbo",
|
63 |
-
],
|
64 |
-
value="ArissBandoss/whisper-small-mos",
|
65 |
-
label="Model Name"
|
66 |
-
),
|
67 |
-
gr.Dropdown(choices=["Automatic Detection"] + sorted(get_language_names()), value="Automatic Detection", label="Language", interactive = True,),
|
68 |
-
gr.Slider(label="Batch Size", minimum=1, maximum=32, value=8, step=1),
|
69 |
-
gr.Slider(label="Chunk Length (s)", minimum=1, maximum=60, value=17.5, step=0.1),
|
70 |
-
gr.Slider(label="Stride Length (s)", minimum=1, maximum=30, value=1, step=0.1),
|
71 |
-
],
|
72 |
-
outputs=[gr.Textbox(label="Output"), gr.File(label="Download Files")],
|
73 |
-
examples=[["./audios/example1.mp3", "a ye ligdi"],
|
74 |
-
["./audios/example2.mp3", "zoe nimbãanega"],
|
75 |
-
["./audios/example3.mp3", "zãng-zãnga"],
|
76 |
-
["./audios/example4.mp3", "yõk foto"]
|
77 |
-
],
|
78 |
-
cache_examples=False,
|
79 |
-
title="Mooré ASR: Transcribe Audio",
|
80 |
-
description=DESCRIPTION,
|
81 |
-
flagging_mode="auto",
|
82 |
-
)
|
83 |
-
|
84 |
-
goai_tts = gr.Interface(
|
85 |
-
fn=goai_tts2.goai_ttt_tts,
|
86 |
-
inputs=[
|
87 |
-
gr.Text(label="Texte à traduire", lines=2, value="Par cette ouverture, le centre se veut contribuer à la formation professionnelle des jeunes et des femmes, renforcer les capacités des acteurs du monde agricole, et contribuer à la lutte contre le chômage au Burkina Faso."),
|
88 |
-
gr.Dropdown(label="Voix", choices=AUDIO_FILES , value="exple_voix_masculine.wav"),
|
89 |
-
gr.Audio(label="Cloner votre voix (optionel)", type="numpy", format="wav"),
|
90 |
-
],
|
91 |
-
outputs=[
|
92 |
-
gr.Text(label="Texte traduit"),
|
93 |
-
gr.Audio(label="Audio original généré", format="wav"),
|
94 |
-
gr.Audio(label="Denoised Audio", format='wav'),
|
95 |
-
gr.Audio(label="Enhanced Audio", format='wav')
|
96 |
-
],
|
97 |
-
examples=[["Ils vont bien, merci. Mon père travaille dur dans les champs et ma mère est toujours occupée à la maison.", "exple_voix_masculine.wav", None],
|
98 |
-
["La finale s’est jouée en présence du Président du Faso, Ibrahim Traoré.", "exple_voix_feminine.wav", None],
|
99 |
-
["Les enfants apprennent les danses traditionnelles de leurs ancêtres, jouent à des jeux traditionnels dans les rues et aident leurs parents dans les tâches quotidiennes.", "exple_voix_masculine.wav", None],
|
100 |
-
["Ils achetèrent des troupeaux, firent construire des cases, parcoururent tout le pays pour offrir à leur mère et à leurs femmes les plus beaux bijoux, les plus belles étoffes.", "exple_voix_feminine.wav", None]
|
101 |
-
],
|
102 |
-
cache_examples=False,
|
103 |
-
title="Démo des Modèles pour le Mooré: Traduction (Text-to-Text) et Synthèse Vocale (Text-to-Speech)",
|
104 |
-
description=DESCRIPTION,
|
105 |
-
)
|
106 |
-
|
107 |
-
goai_traduction = gr.Interface(
|
108 |
-
fn=goai_traduction.goai_traduction,
|
109 |
-
inputs=[
|
110 |
-
gr.Textbox(label="Texte", placeholder="Yaa sõama"),
|
111 |
-
gr.Dropdown(label="Langue source", choices=["fra_Latn", "mos_Latn"], value='fra_Latn'),
|
112 |
-
gr.Dropdown(label="Langue cible", choices=["fra_Latn", "mos_Latn"], value='mos_Latn')
|
113 |
-
],
|
114 |
-
outputs=["text"],
|
115 |
-
examples=[["Yʋʋm a wãn la b kẽesd biig lekolle?", "mos_Latn", "fra_Latn"],
|
116 |
-
["Zak-soab la kasma.", "mos_Latn", "fra_Latn"],
|
117 |
-
["Le gouvernement avait pris des mesures louables par rapport à l’augmentation des prix de certaines denrées alimentaires.", "fra_Latn", "mos_Latn"],
|
118 |
-
["Comme lors du match face à la Côte d’Ivoire, c’est sur un coup de pied arrêté que les Etalons encaissent leur but.", "fra_Latn", "mos_Latn"],
|
119 |
-
],
|
120 |
-
cache_examples=False,
|
121 |
-
title="Traduction du Mooré: texte vers texte",
|
122 |
-
description=DESCRIPTION
|
123 |
-
)
|
124 |
-
|
125 |
-
|
126 |
-
with demo:
|
127 |
-
gr.TabbedInterface(
|
128 |
-
interface_list=[goai_stt, goai_tts, goai_traduction],
|
129 |
-
tab_names=["Microphone & Audio file"]
|
130 |
-
)
|
131 |
-
|
132 |
-
demo.queue().launch(ssr_mode=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|