mboushaba commited on
Commit
ed1c090
·
verified ·
1 Parent(s): 4c18362

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import voice_recognition as vr
3
+
4
+ # Example lists for source and target languages
5
+ source_languages = ["English", "French", "Arabic", "MA-Arabic", "Tagalog", "Cebuano"]
6
+ target_languages = ["English", "French", "Arabic", "MA-Arabic", "Tagalog", "Cebuano"]
7
+
8
+ # Model and task options
9
+ models = ["Whisper", "Google"]
10
+ tasks = ["Transcript", "Transcript and Translate"]
11
+
12
+ # Dictionary mapping language labels to ISO codes
13
+ language_mapping = {
14
+ "English": "en",
15
+ "French": "fr",
16
+ "Arabic": "ar",
17
+ "MA-Arabic": "ar",
18
+ "Tagalog": "tl",
19
+ "Cebuano": "fil-PH"
20
+ }
21
+
22
+ # Method to get the ISO code from a language label
23
+ def get_iso_code(language_label):
24
+ return language_mapping.get(language_label, "en")
25
+
26
+
27
+ # Function to handle the input and return the selections
28
+ def process_inputs(source_lang, target_lang, model, task, audio_mic, audio_upload):
29
+ audio = None
30
+ if audio_mic:
31
+ audio = audio_mic
32
+ elif audio_upload:
33
+ audio = audio_upload
34
+ response = vr.process_audio_recognition(model=model, audio_path=audio, source_lang=get_iso_code(source_lang),
35
+ target_lang=get_iso_code(target_lang), translate= task == "Transcript and Translate")
36
+ return response
37
+ # return {
38
+ # "Source Language": source_lang,
39
+ # "Target Language": target_lang,
40
+ # "Model": model,
41
+ # "Task": task,
42
+ # "Audio Received": "Yes" if audio else "No"
43
+ # }
44
+
45
+
46
+ # Gradio interface setup
47
+ with gr.Blocks(title = "Voice Transcription", theme = gr.themes.Soft()) as demo:
48
+ with gr.Row():
49
+ # Dropdown for source and target languages (display name, return ISO code)
50
+ source_lang_dropdown = gr.Dropdown(label="Source Language", choices=source_languages, value="English")
51
+ target_lang_dropdown = gr.Dropdown(label="Target Language", choices=target_languages, value="French")
52
+ with gr.Row():
53
+ # Dropdown for models and tasks
54
+ model_dropdown = gr.Dropdown(label="Model", choices=models, value=models[0], info="The model that will be used")
55
+ task_dropdown = gr.Dropdown(label="Task", choices=tasks, value=tasks[0], info="Transcript and/or Translate")
56
+
57
+ # Audio input (mic or upload)
58
+ with gr.Tab("Record"):
59
+ audio_input_mic = gr.Audio(sources=["microphone"], type="filepath")
60
+ with gr.Tab("Upload"):
61
+ audio_input_upload = gr.Audio(sources=["upload"], type="filepath")
62
+
63
+ #audio_input = gr.Audio(sources=["microphone"], type="filepath")
64
+ #audio_input2 = gr.Audio(sources=["upload"], type="filepath")
65
+
66
+ # Button to submit
67
+ submit_button = gr.Button("Submit")
68
+
69
+ # Output label to show the selected inputs
70
+ output = gr.Textbox(label="Result")
71
+
72
+ # Link button click to function
73
+ submit_button.click(fn=process_inputs,
74
+ inputs=[source_lang_dropdown, target_lang_dropdown, model_dropdown, task_dropdown, audio_input_mic, audio_input_upload],
75
+ outputs=output)
76
+
77
+ if __name__ == '__main__':
78
+ # check the model rate
79
+ demo.launch(favicon_path = "../favicon.ico")