papasega commited on
Commit
ed59b1d
·
verified ·
1 Parent(s): 627cf36

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+ import httpcore
5
+ from googletrans import Translator
6
+
7
+ # Correctif pour httpcore
8
+ setattr(httpcore, 'SyncHTTPTransport', object)
9
+
10
+ # Initialisation du modèle de transcription
11
+ transcriber = pipeline("automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-arabic")
12
+ # Initialisation du traducteur
13
+ translator = Translator()
14
+
15
+ def transcribe_and_translate(audio):
16
+ sr, y = audio
17
+ y = y.astype(np.float32)
18
+ y /= np.max(np.abs(y))
19
+
20
+ # Transcription du texte
21
+ transcription = transcriber({"sampling_rate": sr, "raw": y})["text"]
22
+ # Traduction du texte transcrit
23
+ translation = translator.translate(transcription, src='ar', dest='fr').text
24
+ return transcription, translation
25
+
26
+ # Création de l'interface Gradio
27
+ demo = gr.Interface(
28
+ fn=transcribe_and_translate,
29
+ inputs=gr.Audio(sources=["microphone"], label="Enregistrement Audio"),
30
+ outputs=[
31
+ gr.Textbox(label="Texte en Arabe"),
32
+ gr.Textbox(label="Traduction en Français")
33
+ ],
34
+ title="S2T-MT: Transcription automatiques de l'Arabe et traduction en Français by PSW",
35
+ description="Utilisez le microphone pour parler en arabe, puis appuyez sur le bouton stop et Submit pour voir la transcription et la traduction."
36
+ )
37
+
38
+ # Lancement de l'application Gradio
39
+ demo.launch(show_error=True, share=True)