Anushkabhat9 commited on
Commit
6892880
·
verified ·
1 Parent(s): 1082bf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -1,23 +1,34 @@
 
1
  import torch
2
  from transformers import pipeline
3
  from datasets import load_dataset
4
 
5
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
6
 
7
- pipe = pipeline(
 
 
 
 
8
  "automatic-speech-recognition",
9
  model="openai/whisper-small",
10
  chunk_length_s=30,
11
- device=device,
12
- )
13
-
14
- ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
15
- sample = ds[0]["audio"]
16
 
17
- prediction = pipe(sample.copy(), batch_size=8)["text"]
 
18
 
19
 
20
- # we can also return timestamps for the predictions
21
- prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
 
 
 
 
 
22
 
23
- print(prediction[0]['text'])
 
 
1
+ import gradio as gr
2
  import torch
3
  from transformers import pipeline
4
  from datasets import load_dataset
5
 
6
+ # device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
 
8
+ # ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
9
+ # sample = ds[0]["audio"]
10
+
11
+ def transcribe_audio(sample):
12
+ pipe = pipeline(
13
  "automatic-speech-recognition",
14
  model="openai/whisper-small",
15
  chunk_length_s=30,
16
+ )
17
+ # prediction = pipe(sample.copy(), batch_size=8)["text"]
18
+ prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
19
+ return prediction
 
20
 
21
+ # we can also return timestamps for the predictions
22
+
23
 
24
 
25
+ interface = gr.Interface(
26
+ fn=transcribe_audio, # The function to be applied to the audio input
27
+ inputs=gr.Audio(type="filepath"), # Users can record or upload audio
28
+ outputs="text", # The output is the transcription (text)
29
+ title="Whisper Small ASR", # Title of your app
30
+ description="Transcription using Whisper Small." # Description of your app
31
+ )
32
 
33
+ # **This line starts the Gradio app**
34
+ interface.launch()