lewtun HF staff commited on
Commit
173f818
β€’
1 Parent(s): e1cf9c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from datasets import load_dataset
4
+
5
+ speech_commands = load_dataset("speech_commands", "v0.02", split="test")
6
+ id2label = speech_commands.features["label"].int2str
7
+
8
+
9
+ def generate_audio():
10
+ example = speech_commands.shuffle()[0]
11
+ audio = example["audio"]
12
+ return (audio["sampling_rate"], (audio["array"] * 32_767).astype(np.int16)), id2label(example["label"])
13
+
14
+
15
+ with gr.Blocks() as demo:
16
+ with gr.Column():
17
+ for _ in range(4):
18
+ audio, label = generate_audio()
19
+ output = gr.Audio(audio, label=label)
20
+
21
+ demo.launch()