Spaces:
Sleeping
Sleeping
TheStinger
commited on
Commit
•
a250d52
1
Parent(s):
043c510
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import os
|
4 |
+
|
5 |
+
def play_random_audio():
|
6 |
+
audio_folder = "audio_files"
|
7 |
+
audio_files = [f for f in os.listdir(audio_folder) if f.endswith('.mp3') or f.endswith('.wav')]
|
8 |
+
chosen_audio = random.choice(audio_files)
|
9 |
+
return os.path.join(audio_folder, chosen_audio)
|
10 |
+
|
11 |
+
with gr.Blocks() as demo:
|
12 |
+
gr.Markdown("## Premere il pulsante per ascoltare un audio casuale")
|
13 |
+
play_button = gr.Button("Riproduci Audio")
|
14 |
+
audio_output = gr.Audio()
|
15 |
+
|
16 |
+
play_button.click(fn=play_random_audio, outputs=audio_output)
|
17 |
+
|
18 |
+
demo.launch()
|