csukuangfj commited on
Commit
81687e9
1 Parent(s): f5b2e32

Minor fixes

Browse files
Files changed (1) hide show
  1. app.py +32 -11
app.py CHANGED
@@ -49,6 +49,9 @@ def process(
49
  print("in_filename", in_filename)
50
  print("language", language)
51
  print("repo_id", repo_id)
 
 
 
52
  filename = convert_to_wav(in_filename)
53
 
54
  now = datetime.now()
@@ -89,7 +92,16 @@ def process(
89
  print("hyp")
90
  print(hyp)
91
 
92
- return hyp
 
 
 
 
 
 
 
 
 
93
 
94
 
95
  title = "# Automatic Speech Recognition with Next-gen Kaldi"
@@ -113,7 +125,16 @@ def update_model_dropdown(language: str):
113
  raise ValueError(f"Unsupported language: {language}")
114
 
115
 
116
- demo = gr.Blocks()
 
 
 
 
 
 
 
 
 
117
 
118
  with demo:
119
  gr.Markdown(title)
@@ -124,7 +145,11 @@ with demo:
124
  choices=language_choices,
125
  value=language_choices[0],
126
  )
127
- model_dropdown = gr.Dropdown(choices=[], label="Select a model")
 
 
 
 
128
  language_radio.change(
129
  update_model_dropdown,
130
  inputs=language_radio,
@@ -146,29 +171,25 @@ with demo:
146
 
147
  with gr.Tabs():
148
  with gr.TabItem("Upload from disk"):
149
- uploaded_file = gr.inputs.Audio(
150
  source="upload", # Choose between "microphone", "upload"
151
  type="filepath",
152
  optional=False,
153
  label="Upload from disk",
154
  )
 
155
  upload_button = gr.Button("Submit for recognition")
156
- uploaded_output = gr.outputs.Textbox(
157
- label="Recognized speech from uploaded file"
158
- )
159
 
160
  with gr.TabItem("Record from microphone"):
161
- microphone = gr.inputs.Audio(
162
  source="microphone", # Choose between "microphone", "upload"
163
  type="filepath",
164
  optional=False,
165
  label="Record from microphone",
166
  )
167
- recorded_output = gr.outputs.Textbox(
168
- label="Recognized speech from recordings"
169
- )
170
 
171
  record_button = gr.Button("Submit for recognition")
 
172
 
173
  upload_button.click(
174
  process,
 
49
  print("in_filename", in_filename)
50
  print("language", language)
51
  print("repo_id", repo_id)
52
+ print("decoding_method", decoding_method)
53
+ print("num_active_paths", num_active_paths)
54
+
55
  filename = convert_to_wav(in_filename)
56
 
57
  now = datetime.now()
 
92
  print("hyp")
93
  print(hyp)
94
 
95
+ html_output = f"""
96
+ <div class='result'>
97
+ <div class='result_item result_item_success'>
98
+ {hyp}
99
+ <br/>
100
+ </div>
101
+ </div>
102
+ """
103
+
104
+ return html_output
105
 
106
 
107
  title = "# Automatic Speech Recognition with Next-gen Kaldi"
 
125
  raise ValueError(f"Unsupported language: {language}")
126
 
127
 
128
+ # The css style is copied from
129
+ # https://huggingface.co/spaces/alphacep/asr/blob/main/app.py#L112
130
+ demo = gr.Blocks(
131
+ css="""
132
+ .result {display:flex;flex-direction:column}
133
+ .result_item {padding:15px;margin-bottom:8px;border-radius:15px;width:100%}
134
+ .result_item_success {background-color:mediumaquamarine;color:white;align-self:start}
135
+ .result_item_error {background-color:#ff7070;color:white;align-self:start}
136
+ """,
137
+ )
138
 
139
  with demo:
140
  gr.Markdown(title)
 
145
  choices=language_choices,
146
  value=language_choices[0],
147
  )
148
+ model_dropdown = gr.Dropdown(
149
+ choices=language_to_models[language_choices[0]],
150
+ label="Select a model",
151
+ )
152
+
153
  language_radio.change(
154
  update_model_dropdown,
155
  inputs=language_radio,
 
171
 
172
  with gr.Tabs():
173
  with gr.TabItem("Upload from disk"):
174
+ uploaded_file = gr.Audio(
175
  source="upload", # Choose between "microphone", "upload"
176
  type="filepath",
177
  optional=False,
178
  label="Upload from disk",
179
  )
180
+ uploaded_output = gr.HTML(label="Recognized speech from uploaded file")
181
  upload_button = gr.Button("Submit for recognition")
 
 
 
182
 
183
  with gr.TabItem("Record from microphone"):
184
+ microphone = gr.Audio(
185
  source="microphone", # Choose between "microphone", "upload"
186
  type="filepath",
187
  optional=False,
188
  label="Record from microphone",
189
  )
 
 
 
190
 
191
  record_button = gr.Button("Submit for recognition")
192
+ recorded_output = gr.HTML(label="Recognized speech from recordings")
193
 
194
  upload_button.click(
195
  process,