NeoPy commited on
Commit
ed34ab2
·
verified ·
1 Parent(s): 44f5898

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -55
app.py CHANGED
@@ -1,63 +1,60 @@
1
  import gradio as gr
 
 
2
 
3
- def demo_interface():
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
- # Actual tabs
26
- with gr.Tabs():
27
- with gr.Tab("Tabs 1"):
28
- # Replace with any components you want
29
- gr.Markdown(
30
- """
31
- <div style="text-align: center;">
32
- <h3>All options 1</h3>
33
- <!-- Put your controls, sliders, textboxes, etc. here -->
34
- </div>
35
- """
36
- )
 
 
37
 
38
- with gr.Tab("Tabs 2"):
39
- # Replace with any components you want
40
- gr.Markdown(
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
- # Credits label at the bottom
50
- gr.Markdown(
51
- """
52
- <p style="text-align: center; margin-top: 2rem;">
53
- CREDITS Label
54
- </p>
55
- """,
56
- elem_id="credits_label"
57
- )
58
-
59
- return demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  if __name__ == "__main__":
62
- ui = demo_interface()
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)