patrickvonplaten commited on
Commit
46a0d52
1 Parent(s): 70ec95c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -15,18 +15,30 @@ def process_audio_file(file):
15
  input_values = feature_extractor(data, return_tensors="pt").input_values
16
  return input_values
17
 
18
- def transcribe(file):
 
 
 
 
 
 
 
 
 
 
 
19
  input_values = process_audio_file(file)
20
 
21
  sequences = model.generate(input_values, num_beams=1, max_length=30)
22
 
23
  transcription = tokenizer.batch_decode(sequences, skip_special_tokens=True)
24
- return transcription[0]
25
 
26
  iface = gr.Interface(
27
  fn=transcribe,
28
  inputs=[
29
- gr.inputs.Audio(source="microphone", type='filepath'),
 
30
  ],
31
  outputs="text",
32
  layout="horizontal",
15
  input_values = feature_extractor(data, return_tensors="pt").input_values
16
  return input_values
17
 
18
+ def transcribe(file_mic, file_upload):
19
+ warn_output = ""
20
+ if (file_mic is not None) and (file_upload is not None):
21
+ warn_output = "WARNING: You've uploaded an audio file and used the microphone. The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
22
+ file = file_mic
23
+ elif (file_mic is None) and (file_upload is None):
24
+ return "ERROR: You have to either use the microphone or upload an audio file"
25
+ elif file_mic is not None:
26
+ file = file_mic
27
+ else:
28
+ file = file_upload
29
+
30
  input_values = process_audio_file(file)
31
 
32
  sequences = model.generate(input_values, num_beams=1, max_length=30)
33
 
34
  transcription = tokenizer.batch_decode(sequences, skip_special_tokens=True)
35
+ return warn_output + transcription[0]
36
 
37
  iface = gr.Interface(
38
  fn=transcribe,
39
  inputs=[
40
+ gr.inputs.Audio(source="microphone", type='filepath', optional=True),
41
+ gr.inputs.Audio(source="upload", type='filepath', optional=True),
42
  ],
43
  outputs="text",
44
  layout="horizontal",