Kryptone commited on
Commit
28c73d5
·
1 Parent(s): 635ad89

added misc tools and changed theme

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr, glob, os, auditok, random, zipfile, wave, pytube.exceptions
2
  from pytube import YouTube
3
  from moviepy.editor import VideoFileClip
4
- import auditok
5
 
6
  def download_video(url):
7
  try:
@@ -76,7 +75,29 @@ def split_audio(mindur, maxdur, name_for_split_files, show_amount_of_files_and_f
76
  os.remove(file2)
77
  return f"Files split successfully!\n\nCheck below for zipped files.\n\n{total_files} files created, {length_mins:.2f} minutes total.", zip_file_name
78
 
79
- with gr.Blocks(theme=gr.themes.Soft(), title="Global Dataset Maker") as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  gr.HTML(
81
  "<h1> Welcome to the GDMGS! (GlobalDatasetMaker Gradio Space) </h1>"
82
  )
@@ -109,5 +130,18 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Global Dataset Maker") as app:
109
  inputs=[mindur, maxdur, name_for_split_files, show_amount_of_files_and_file_dur],
110
  outputs=[gr.Text(label="Output"), gr.File(label="Zipped files")]
111
  )
112
-
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  app.launch()
 
1
  import gradio as gr, glob, os, auditok, random, zipfile, wave, pytube.exceptions
2
  from pytube import YouTube
3
  from moviepy.editor import VideoFileClip
 
4
 
5
  def download_video(url):
6
  try:
 
75
  os.remove(file2)
76
  return f"Files split successfully!\n\nCheck below for zipped files.\n\n{total_files} files created, {length_mins:.2f} minutes total.", zip_file_name
77
 
78
+ def analyze_audio(zip_file_path):
79
+ with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
80
+ zip_ref.extractall('unzipped_files')
81
+ total_sample_rate = 0
82
+ total_files = 0
83
+ for file_name in os.listdir('unzipped_files'):
84
+ if file_name.lower().endswith('.wav'):
85
+ file_path = os.path.join('unzipped_files', file_name)
86
+ try:
87
+ with wave.open(file_path, 'r') as audio_file:
88
+ sample_rate = audio_file.getframerate()
89
+ total_sample_rate += sample_rate
90
+ total_files += 1
91
+ except wave.Error as e:
92
+ print(f"Error reading file: {e}")
93
+ if total_files > 0:
94
+ average_sample_rate = total_sample_rate / total_files
95
+ return f"Average sample rate: {average_sample_rate}"
96
+ else:
97
+ return "No average sample rate could be found."
98
+
99
+
100
+ with gr.Blocks(theme=gr.themes.Monochrome(), title="Global Dataset Maker") as app:
101
  gr.HTML(
102
  "<h1> Welcome to the GDMGS! (GlobalDatasetMaker Gradio Space) </h1>"
103
  )
 
130
  inputs=[mindur, maxdur, name_for_split_files, show_amount_of_files_and_file_dur],
131
  outputs=[gr.Text(label="Output"), gr.File(label="Zipped files")]
132
  )
133
+ with gr.TabItem("Misc tools"):
134
+ with gr.Tab("SR analyzer"):
135
+ gr.Markdown("Upload a zip file of your wavs here and this will determine the average sample rate.")
136
+ with gr.Row():
137
+ with gr.Column():
138
+ with gr.Row():
139
+ zipuploader = gr.File(file_count='single', file_types=[".zip"], label="ZIP file")
140
+ uploadbtn = gr.Button("Analyze", variant='primary')
141
+ uploadbtn.click(
142
+ analyze_audio,
143
+ [zipuploader],
144
+ [gr.Text(label="Result")]
145
+ )
146
+
147
  app.launch()