hexular commited on
Commit
4034654
1 Parent(s): 24e0e26

Update syntax

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -7,24 +7,38 @@ BATCH_SIZE = 8
7
 
8
  device = 0 if torch.cuda.is_available() else "cpu"
9
 
10
- pipe = pipeline(
11
  task="automatic-speech-recognition",
12
  model=MODEL_NAME,
13
  chunk_length_s=30,
14
  device=device,
15
  )
16
 
17
- def transcribe(audio):
18
- print(audio)
19
- result = pipe(audio, batch_size=BATCH_SIZE)["text"]
20
- print(result)
21
-
22
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  demo = gr.Blocks()
25
 
26
- app = gr.Interface(fn=transcribe, inputs=gr.inputs.Audio(source="microphone", type="filepath"), outputs="textbox")
27
  with demo:
28
- gr.TabbedInterface([app], "Mic")
29
-
30
- demo.launch()
 
 
 
7
 
8
  device = 0 if torch.cuda.is_available() else "cpu"
9
 
10
+ asr = pipeline(
11
  task="automatic-speech-recognition",
12
  model=MODEL_NAME,
13
  chunk_length_s=30,
14
  device=device,
15
  )
16
 
17
+ def transcribe(filepath):
18
+ if filepath is None:
19
+ gr.Warning("No audio found, please retry.")
20
+ return ""
21
+ output = asr(
22
+ filepath,
23
+ max_new_tokens=256,
24
+ chunk_length_s=30,
25
+ batch_size=8,
26
+ )
27
+ return output["text"]
28
+
29
+ mic_transcribe = gr.Interface(
30
+ fn=transcribe,
31
+ inputs=gr.Audio(sources="microphone",
32
+ type="filepath"),
33
+ outputs=gr.Textbox(label="Transcription",
34
+ lines=3),
35
+ allow_flagging="never")
36
 
37
  demo = gr.Blocks()
38
 
 
39
  with demo:
40
+ gr.TabbedInterface(
41
+ [mic_transcribe],
42
+ ["Transcribe Microphone"],
43
+ )
44
+ demo.launch(share=True)