Kryptone commited on
Commit
0ba0222
·
verified ·
1 Parent(s): 087b155

check changelog tab again, for real this time

Browse files
Files changed (1) hide show
  1. app.py +14 -34
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr, glob, os, auditok, zipfile, wave, pytube.exceptions, librosa, time, librosa, librosa.display, matplotlib.pyplot as plt, numpy as np
2
  from pytube import YouTube
3
  from moviepy.editor import VideoFileClip
4
 
@@ -7,6 +7,10 @@ def download_video(url, download_as):
7
  yt = YouTube(url)
8
  except pytube.exceptions.RegexMatchError:
9
  raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
 
 
 
 
10
  video = yt.streams.get_highest_resolution()
11
  video.download()
12
  video_path = f"{video.default_filename}"
@@ -79,27 +83,6 @@ def split_audio_from_yt_video(mindur, maxdur, name_for_split_files, show_amount_
79
  os.remove(file2)
80
  return f"Files split successfully!\nCheck below for zipped files.\n\n{total_files} files created, {length_mins:.2f} minutes total.", zip_file_name
81
 
82
- def analyze_audio(zip_file_path):
83
- with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
84
- zip_ref.extractall('unzipped_files')
85
- total_sample_rate = 0
86
- total_files = 0
87
- for file_name in os.listdir('unzipped_files'):
88
- if file_name.lower().endswith('.wav'):
89
- file_path = os.path.join('unzipped_files', file_name)
90
- try:
91
- with wave.open(file_path, 'r') as audio_file:
92
- sample_rate = audio_file.getframerate()
93
- total_sample_rate += sample_rate
94
- total_files += 1
95
- except wave.Error as e:
96
- print(f"Error reading file: {e}")
97
- if total_files > 0:
98
- average_sample_rate = total_sample_rate / total_files
99
- return f"Average sample rate: {average_sample_rate}"
100
- else:
101
- return "No average sample rate could be found."
102
-
103
  def split_wav_or_mp3_file(audiofileuploader, mindur2, maxdur2, name_for_split_files2):
104
  if audiofileuploader == None:
105
  raise gr.Error("Audio file cannot be empty!")
@@ -146,6 +129,10 @@ def all_in_one_inator(ytvideo, download_yt_video_as, min_duration, max_duration,
146
  yt = YouTube(ytvideo)
147
  except pytube.exceptions.RegexMatchError:
148
  raise gr.Error("URL not valid or was left empty! Please fix the link or enter one.")
 
 
 
 
149
  video = yt.streams.get_highest_resolution()
150
  video.download()
151
  video_path = f"{video.default_filename}"
@@ -188,6 +175,10 @@ def download_video_as_audio_only(yt_video, audio_output_format):
188
  yt = YouTube(yt_video)
189
  except pytube.exceptions.RegexMatchError:
190
  raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
 
 
 
 
191
  video = yt.streams.get_highest_resolution()
192
  video.download()
193
  video_path = f"{video.default_filename}"
@@ -277,18 +268,6 @@ with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") a
277
  outputs=[gr.Text(label="Output"), gr.File(label="Zipped files")]
278
  )
279
  with gr.TabItem("Misc tools"):
280
- with gr.Tab("SR analyzer"):
281
- gr.Markdown("Upload a zip file of your wavs here and this will determine the average sample rate.")
282
- with gr.Row():
283
- with gr.Column():
284
- with gr.Row():
285
- zipuploader = gr.File(file_count='single', file_types=[".zip"], label="ZIP file")
286
- uploadbtn = gr.Button("Analyze", variant='primary')
287
- uploadbtn.click(
288
- analyze_audio,
289
- [zipuploader],
290
- [gr.Text(label="Result")]
291
- )
292
  with gr.Tab("File splitter"):
293
  gr.Markdown("If you would rather split a single WAV or mp3 audio file, use this method instead.")
294
  with gr.Row():
@@ -357,6 +336,7 @@ with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") a
357
  gr.Image(label="Spectrogram result", show_download_button=False, scale=2)
358
  )
359
  with gr.TabItem("Changelog"):
 
360
  gr.Markdown("v0.97a - Fixed issue with spectrogram tab if no WAV file was selected.")
361
  gr.Markdown("v0.97 - Added new spectrogram tool in Misc Tools and removed pitch analyzer as it did not fit with the purpose of this Space.")
362
  gr.Markdown("v0.96 - Added new remaining files tool in Misc Tools.")
 
1
+ import gradio as gr, glob, os, auditok, zipfile, wave, pytube.exceptions, librosa, time, librosa, librosa.display, matplotlib.pyplot as plt, numpy as np, urllib.error
2
  from pytube import YouTube
3
  from moviepy.editor import VideoFileClip
4
 
 
7
  yt = YouTube(url)
8
  except pytube.exceptions.RegexMatchError:
9
  raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
10
+ except urllib.error.HTTPError as not_ok:
11
+ raise gr.Error(f"Recieved {not_ok}")
12
+ except pytube.exceptions.AgeRestrictedError:
13
+ raise gr.Error("The video you inputted is age-restricted! Please try another link.")
14
  video = yt.streams.get_highest_resolution()
15
  video.download()
16
  video_path = f"{video.default_filename}"
 
83
  os.remove(file2)
84
  return f"Files split successfully!\nCheck below for zipped files.\n\n{total_files} files created, {length_mins:.2f} minutes total.", zip_file_name
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  def split_wav_or_mp3_file(audiofileuploader, mindur2, maxdur2, name_for_split_files2):
87
  if audiofileuploader == None:
88
  raise gr.Error("Audio file cannot be empty!")
 
129
  yt = YouTube(ytvideo)
130
  except pytube.exceptions.RegexMatchError:
131
  raise gr.Error("URL not valid or was left empty! Please fix the link or enter one.")
132
+ except urllib.error.HTTPError as not_ok:
133
+ raise gr.Error(f"Recieved {not_ok}")
134
+ except pytube.exceptions.AgeRestrictedError:
135
+ raise gr.Error("The video you inputted is age-restricted! Please try another link.")
136
  video = yt.streams.get_highest_resolution()
137
  video.download()
138
  video_path = f"{video.default_filename}"
 
175
  yt = YouTube(yt_video)
176
  except pytube.exceptions.RegexMatchError:
177
  raise gr.Error("URL not valid or is empty! Please fix the link or enter one!")
178
+ except urllib.error.HTTPError as not_ok:
179
+ raise gr.Error(f"Recieved {not_ok}")
180
+ except pytube.exceptions.AgeRestrictedError:
181
+ raise gr.Error("The video you inputted is age-restricted! Please try another link.")
182
  video = yt.streams.get_highest_resolution()
183
  video.download()
184
  video_path = f"{video.default_filename}"
 
268
  outputs=[gr.Text(label="Output"), gr.File(label="Zipped files")]
269
  )
270
  with gr.TabItem("Misc tools"):
 
 
 
 
 
 
 
 
 
 
 
 
271
  with gr.Tab("File splitter"):
272
  gr.Markdown("If you would rather split a single WAV or mp3 audio file, use this method instead.")
273
  with gr.Row():
 
336
  gr.Image(label="Spectrogram result", show_download_button=False, scale=2)
337
  )
338
  with gr.TabItem("Changelog"):
339
+ gr.Markdown("v0.98.1 - Reverted back due to none of the new features working apart from removing SR analyzer and adding new error checks.")
340
  gr.Markdown("v0.97a - Fixed issue with spectrogram tab if no WAV file was selected.")
341
  gr.Markdown("v0.97 - Added new spectrogram tool in Misc Tools and removed pitch analyzer as it did not fit with the purpose of this Space.")
342
  gr.Markdown("v0.96 - Added new remaining files tool in Misc Tools.")