Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,60 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
with gr.Blocks() as demo:
|
5 |
-
# Top label
|
6 |
-
gr.Markdown(
|
7 |
-
"""
|
8 |
-
<h1 style="text-align: center; margin-bottom: 1rem;">
|
9 |
-
LABEL
|
10 |
-
</h1>
|
11 |
-
""",
|
12 |
-
elem_id="top_label"
|
13 |
-
)
|
14 |
|
15 |
-
# Main Tabs label
|
16 |
-
gr.Markdown(
|
17 |
-
"""
|
18 |
-
<h2 style="text-align: center; margin-bottom: 1rem;">
|
19 |
-
MAIN TABS
|
20 |
-
</h2>
|
21 |
-
""",
|
22 |
-
elem_id="main_tabs_label"
|
23 |
-
)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
<div style="text-align: center;">
|
43 |
-
<h3>All options 2</h3>
|
44 |
-
<!-- Put your controls, sliders, textboxes, etc. here -->
|
45 |
-
</div>
|
46 |
-
"""
|
47 |
-
)
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
if __name__ == "__main__":
|
62 |
-
|
63 |
-
ui.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
import os
|
4 |
|
5 |
+
directory = "./audios"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def scan_audio_folder():
|
9 |
+
"""Scan directory for audio files and return list of paths."""
|
10 |
+
supported_formats = ['.mp3', '.wav', '.m4a']
|
11 |
+
audio_files = []
|
12 |
+
|
13 |
+
try:
|
14 |
+
for root, _, files in os.walk(directory):
|
15 |
+
for file in files:
|
16 |
+
if os.path.splitext(file)[1].lower() in supported_formats:
|
17 |
+
audio_files.append(os.path.join(root, file))
|
18 |
+
return sorted(audio_files)
|
19 |
+
except Exception as e:
|
20 |
+
print(f"Error scanning directory: {str(e)}")
|
21 |
+
return []
|
22 |
|
23 |
+
def update_audio_list(folder_path):
|
24 |
+
"""Update audio dropdown based on selected folder."""
|
25 |
+
audio_files = scan_audio_folder(folder_path)
|
26 |
+
return gr.Dropdown.update(choices=[Path(f).name for f in audio_files])
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Initialize the app
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
# Input components
|
31 |
+
folder_input = gr.Textbox(label="Audio Folder Path")
|
32 |
+
|
33 |
+
# Dropdown for selecting audio files
|
34 |
+
audio_dropdown = gr.Dropdown(label="Select Audio File")
|
35 |
+
|
36 |
+
# Audio player component
|
37 |
+
audio_player = gr.Audio(label="Audio Player")
|
38 |
+
|
39 |
+
# Events
|
40 |
+
folder_input.change(
|
41 |
+
fn=update_audio_list,
|
42 |
+
inputs=[folder_input],
|
43 |
+
outputs=[audio_dropdown]
|
44 |
+
)
|
45 |
+
|
46 |
+
audio_dropdown.change(
|
47 |
+
fn=lambda x, f: os.path.join(f, x),
|
48 |
+
inputs=[audio_dropdown, folder_input],
|
49 |
+
outputs=[audio_player]
|
50 |
+
)
|
51 |
+
|
52 |
+
# Layout
|
53 |
+
demo.append(gr.Column([
|
54 |
+
folder_input,
|
55 |
+
audio_dropdown,
|
56 |
+
audio_player
|
57 |
+
]))
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
+
demo.launch(debug=True)
|
|