papasega commited on
Commit
711e3aa
1 Parent(s): 49a1b0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -57
app.py CHANGED
@@ -18,74 +18,29 @@ transcriber = pipeline("automatic-speech-recognition", model="tarteel-ai/whisper
18
  # Initialisation du traducteur
19
  translator = Translator()
20
 
21
- # def transcribe_and_translate(audio):
22
- # sr, y = audio
23
- # y = y.astype(np.float32)
24
- # y /= np.max(np.abs(y))
25
-
26
- # # Transcription du texte
27
- # transcription = transcriber({"sampling_rate": sr, "raw": y})["text"]
28
- # time.sleep(2)
29
- # # Traduction du texte transcrit
30
- # translation = translator.translate(transcription, src='ar', dest='fr').text
31
- # return transcription, translation
32
-
33
- # # Création de l'interface Gradio
34
- # demo = gr.Interface(
35
- # fn=transcribe_and_translate,
36
- # inputs=gr.Audio(sources=["microphone"], label="Enregistrement Audio"),
37
- # outputs=[
38
- # gr.Textbox(label="Texte en Arabe"),
39
- # gr.Textbox(label="Traduction en Français")
40
- # ],
41
- # title="Transcription automatiques de l'Arabe et traduction en Français by PSW",
42
- # description="Utilisez le microphone pour parler en arabe, puis appuyez sur le bouton stop et Submit pour voir la transcription et la traduction."
43
- # )
44
-
45
- # # Lancement de l'application Gradio
46
- # demo.launch(show_error=True, share=True)
47
-
48
-
49
- def transcribe(audio):
50
  sr, y = audio
51
  y = y.astype(np.float32)
52
  y /= np.max(np.abs(y))
53
 
54
  # Transcription du texte
55
  transcription = transcriber({"sampling_rate": sr, "raw": y})["text"]
56
- return transcription
57
-
58
- def translate(transcription):
59
  # Traduction du texte transcrit
60
  translation = translator.translate(transcription, src='ar', dest='fr').text
61
- return translation
62
-
63
 
64
  # Création de l'interface Gradio
65
- audio_input = gr.Audio(sources=["microphone"], label="Enregistrement Audio")
66
- transcription_output = gr.Textbox(label="Texte en Arabe")
67
- translation_output = gr.Textbox(label="Traduction en Français")
68
-
69
- def process_audio(audio):
70
- # Transcription
71
- transcription = transcribe(audio)
72
- # Afficher la transcription
73
- with transcription_output:
74
- print("Transcription:", transcription)
75
- # Traduction après la transcription
76
- translation = translate(transcription)
77
- # Afficher la traduction
78
- with translation_output:
79
- print("Traduction:", translation)
80
-
81
- # Interface Gradio
82
  demo = gr.Interface(
83
- fn=process_audio,
84
- inputs=audio_input,
85
- outputs=[transcription_output, translation_output],
86
- title="Transcription et Traduction Automatiques de l'Arabe en Français",
87
- description="Utilisez le microphone pour parler en arabe, puis appuyez sur le bouton pour voir la transcription et la traduction."
 
 
 
88
  )
89
 
90
  # Lancement de l'application Gradio
91
- demo.launch(show_error=True, share=True)
 
18
  # Initialisation du traducteur
19
  translator = Translator()
20
 
21
+ def transcribe_and_translate(audio):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  sr, y = audio
23
  y = y.astype(np.float32)
24
  y /= np.max(np.abs(y))
25
 
26
  # Transcription du texte
27
  transcription = transcriber({"sampling_rate": sr, "raw": y})["text"]
28
+ time.sleep(2)
 
 
29
  # Traduction du texte transcrit
30
  translation = translator.translate(transcription, src='ar', dest='fr').text
31
+ return transcription, translation
 
32
 
33
  # Création de l'interface Gradio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  demo = gr.Interface(
35
+ fn=transcribe_and_translate,
36
+ inputs=gr.Audio(sources=["microphone"], label="Enregistrement Audio"),
37
+ outputs=[
38
+ gr.Textbox(label="Texte en Arabe"),
39
+ gr.Textbox(label="Traduction en Français")
40
+ ],
41
+ title="Transcription automatiques de l'Arabe et traduction en Français by PSW",
42
+ description="Utilisez le microphone pour parler en arabe, puis appuyez sur le bouton stop et Submit pour voir la transcription et la traduction."
43
  )
44
 
45
  # Lancement de l'application Gradio
46
+ demo.launch(show_error=True, share=True)