Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
|
| 5 |
+
gtzan = load_dataset("marsyas/gtzan", split="train")
|
| 6 |
+
id2label = gtzan.features["genre"].int2str
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def generate_audio():
|
| 10 |
+
example = gtzan.shuffle()[0]
|
| 11 |
+
audio = example["audio"]
|
| 12 |
+
return (
|
| 13 |
+
audio["sampling_rate"],
|
| 14 |
+
audio["array"],
|
| 15 |
+
), id2label(example["genre"])
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
with gr.Column():
|
| 20 |
+
for _ in range(4):
|
| 21 |
+
audio, label = generate_audio()
|
| 22 |
+
output = gr.Audio(audio, label=label)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|