Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,28 +3,32 @@ from transformers import pipeline
|
|
3 |
|
4 |
|
5 |
|
6 |
-
device = "cuda:0" if torch.cuda.is_available() else "
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
)
|
14 |
|
15 |
-
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
16 |
-
sample = ds[0]["audio"]
|
17 |
-
|
18 |
-
prediction = pipe(sample.copy(), batch_size=8)["text"]
|
19 |
-
" Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel."
|
20 |
-
|
21 |
-
# we can also return timestamps for the predictions
|
22 |
-
prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
|
23 |
-
[{'text': ' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.',
|
24 |
-
'timestamp': (0.0, 5.44)}]
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
gradio_app.launch()
|
|
|
3 |
|
4 |
|
5 |
|
6 |
+
device = "cuda:0" if torch.cuda.is_available() else "CPU"
|
7 |
+
|
8 |
+
def transcribe(audio):
|
9 |
+
|
10 |
+
pipe = pipeline(
|
11 |
+
"automatic-speech-recognition",
|
12 |
+
model="openai/whisper-small",
|
13 |
+
chunk_length_s=30,
|
14 |
+
device=device,
|
15 |
+
)
|
16 |
+
|
17 |
+
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
18 |
+
sample = ds[0]["audio"]
|
19 |
+
|
20 |
+
prediction = pipe(sample.copy(), batch_size=8)["text"]
|
21 |
+
" Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel."
|
22 |
+
|
23 |
+
return prediction
|
24 |
+
|
25 |
+
gradio_app = gr.Interface(
|
26 |
+
prediction,
|
27 |
+
inputs=gr.Image(label="Input", sources=['audio'], type="pil"),
|
28 |
+
outputs=[gr.Image(label="Ouput"), gr.Label(label="Result", num_top_classes=2)],
|
29 |
+
title="Transcribed",
|
30 |
)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
gradio_app.launch()
|