Azuremis commited on
Commit
8f8ee33
1 Parent(s): a18807a

Add application file

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ from pybraille import convertText
4
+
5
+
6
+ # Translate speech to braille
7
+ def speech_to_text(audio):
8
+ """
9
+
10
+ :param audio: Speech data
11
+ :return: Transcript of speech data
12
+ """
13
+ model = whisper.load_model('base')
14
+
15
+ return model.transcribe(audio)
16
+
17
+
18
+ def transcribe_audio(audio, store=None):
19
+ """
20
+
21
+ :param audio: Speech data from gradio interface
22
+ :param store: Container for user data
23
+ :return: Detected language, transcript text, braille translation, session state
24
+ """
25
+ if store is None:
26
+ store = {}
27
+
28
+ result = speech_to_text(audio)
29
+ store['transcription'] = result['text']
30
+ store['braille'] = convertText(store['transcription'])
31
+
32
+ return f"Detected language: {result['language']}", store[
33
+ 'transcription'], store['braille'], store
34
+
35
+
36
+ # Setup gradio interface
37
+ title = "Speech to Braille Translator"
38
+ transcription_tb = gr.Textbox(label="Transcription", lines=10, max_lines=20)
39
+ detected_lang = gr.outputs.HTML(label="Detected Language")
40
+ transcription_braille = gr.Textbox(label="Braille", lines=10, max_lines=20)
41
+
42
+ state = gr.State({"transcription": ""})
43
+
44
+ demo = gr.Interface(fn=transcribe_audio,
45
+ inputs=[
46
+ gr.Audio(source="microphone", type="filepath",
47
+ streaming=False),
48
+ state
49
+ ],
50
+ outputs=[
51
+ detected_lang,
52
+ transcription_tb,
53
+ transcription_braille,
54
+ state,
55
+ ],
56
+ # live=True,
57
+ allow_flagging='never',
58
+ title=title,
59
+ )
60
+
61
+ # Launch gradio app
62
+ demo.launch()