check changelog for new update details
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 1 | 
         
            -
            import gradio as gr, glob, os, auditok, zipfile, wave, pytube.exceptions, librosa
         
     | 
| 2 | 
         
             
            from pytube import YouTube
         
     | 
| 3 | 
         
             
            from moviepy.editor import VideoFileClip
         
     | 
| 4 | 
         | 
| 
         @@ -146,6 +146,62 @@ def get_average_pitch(audio_file): 
     | 
|
| 146 | 
         
             
                    mean_pitch = pitches.mean()
         
     | 
| 147 | 
         
             
                    return f"Average pitch: {mean_pitch:.2f} Hz"
         
     | 
| 148 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 149 | 
         
             
            with gr.Blocks(theme='NoCrypt/miku', title="Global Dataset Maker") as app:
         
     | 
| 150 | 
         
             
                gr.HTML(
         
     | 
| 151 | 
         
             
                    "<h1> Welcome to the GDMGS! (GlobalDatasetMaker Gradio Space) </h1>"
         
     | 
| 
         @@ -222,7 +278,24 @@ with gr.Blocks(theme='NoCrypt/miku', title="Global Dataset Maker") as app: 
     | 
|
| 222 | 
         
             
                                    [upload],
         
     | 
| 223 | 
         
             
                                    [gr.Text(label="Result")]
         
     | 
| 224 | 
         
             
                                )
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 225 | 
         
             
                    with gr.TabItem("Changelog"):
         
     | 
| 
         | 
|
| 226 | 
         
             
                        gr.Markdown("v0.91 - Added mp3 file support for single file splitting, and also fixed bug if neither output.wav or output.mp3 exists.")
         
     | 
| 227 | 
         
             
                        gr.Markdown("v0.90a - Fixed bug that if 'show_amount_of_files_and_file_dur' was False, split wav files would not be deleted.")
         
     | 
| 228 | 
         
             
                        gr.Markdown("v0.90 - Added mp3 support for downloading a Youtube video.")
         
     | 
| 
         | 
|
| 1 | 
         
            +
            import gradio as gr, glob, os, auditok, zipfile, wave, pytube.exceptions, librosa, time
         
     | 
| 2 | 
         
             
            from pytube import YouTube
         
     | 
| 3 | 
         
             
            from moviepy.editor import VideoFileClip
         
     | 
| 4 | 
         | 
| 
         | 
|
| 146 | 
         
             
                    mean_pitch = pitches.mean()
         
     | 
| 147 | 
         
             
                    return f"Average pitch: {mean_pitch:.2f} Hz"
         
     | 
| 148 | 
         | 
| 149 | 
         
            +
            def all_in_one_inator(ytvideo, download_yt_video_as, min_duration, max_duration, name_for_outputted_split_files, progress=gr.Progress()):
         
     | 
| 150 | 
         
            +
                if download_as == "mp3":
         
     | 
| 151 | 
         
            +
                    gr.Warning("MP3 is experimental, especially with this, so caution is advised.")
         
     | 
| 152 | 
         
            +
                if not os.path.exists("output.wav") and os.path.exists("output.mp3"):
         
     | 
| 153 | 
         
            +
                    gr.Warning("Output.wav does not exist, but output.mp3 does. Splitting MP3 file instead...")
         
     | 
| 154 | 
         
            +
                if not os.path.exists("output.mp3") and os.path.exists("output.wav"):
         
     | 
| 155 | 
         
            +
                    gr.Warning("Output.mp3 does not exist, but output.wav does. Splitting WAV file instead...")
         
     | 
| 156 | 
         
            +
                if min_duration == max_duration:
         
     | 
| 157 | 
         
            +
                    raise gr.Error(f"Cannot split mindur={min_duration} and maxdur={max_duration}, min and max are the same number.")
         
     | 
| 158 | 
         
            +
                elif min_duration > max_duration:
         
     | 
| 159 | 
         
            +
                    raise gr.Error(f"Cannot split mindur={mindur} and maxdur={maxdur}, mindur is higher than maxdur.")
         
     | 
| 160 | 
         
            +
                elif name_for_outputted_split_files == None:
         
     | 
| 161 | 
         
            +
                    raise gr.Error("Split files name cannot be empty! This will be replaced with an alternative naming style in the future.")
         
     | 
| 162 | 
         
            +
                else:
         
     | 
| 163 | 
         
            +
                    try:
         
     | 
| 164 | 
         
            +
                        progress(0, "Downloading video...")
         
     | 
| 165 | 
         
            +
                        yt = YouTube(ytvideo)
         
     | 
| 166 | 
         
            +
                    except pytube.exceptions.RegexMatchError:
         
     | 
| 167 | 
         
            +
                        raise gr.Error("URL no valid or was left empty! Please fix the link or enter one.")
         
     | 
| 168 | 
         
            +
                    video = yt.streams.get_highest_resolution()
         
     | 
| 169 | 
         
            +
                    video.download()
         
     | 
| 170 | 
         
            +
                    video_path = f"{video.default_filename}"
         
     | 
| 171 | 
         
            +
                    video_clip = VideoFileClip(video_path)
         
     | 
| 172 | 
         
            +
                    audio_clip = video_clip.audio
         
     | 
| 173 | 
         
            +
                    if download_yt_video_as == "wav":
         
     | 
| 174 | 
         
            +
                        audio_clip.write_audiofile("output.wav")
         
     | 
| 175 | 
         
            +
                    elif download_yt_video_as == "mp3":
         
     | 
| 176 | 
         
            +
                        audio_clip.write_audiofile("output.mp3")
         
     | 
| 177 | 
         
            +
                    audio_clip.close()
         
     | 
| 178 | 
         
            +
                    video_clip.close()
         
     | 
| 179 | 
         
            +
                    for removemp4 in glob.glob("*.mp4"):
         
     | 
| 180 | 
         
            +
                        os.remove(removemp4)
         
     | 
| 181 | 
         
            +
                    progress(0.5, "Video downloaded! Starting split process...")
         
     | 
| 182 | 
         
            +
                    audio_path = "output.wav" if not os.path.exists("output.mp3") else "output.mp3"
         
     | 
| 183 | 
         
            +
                    audio_regions = auditok.split(
         
     | 
| 184 | 
         
            +
                        audio_path,
         
     | 
| 185 | 
         
            +
                        min_dur=min_duration,
         
     | 
| 186 | 
         
            +
                        max_dur=max_duration,
         
     | 
| 187 | 
         
            +
                        max_silence=0.3,
         
     | 
| 188 | 
         
            +
                        energy_threshold=45
         
     | 
| 189 | 
         
            +
                    )
         
     | 
| 190 | 
         
            +
                    os.remove(audio_path)
         
     | 
| 191 | 
         
            +
                    for i, r in enumerate(audio_regions):
         
     | 
| 192 | 
         
            +
                        filename = r.save(f"{name_for_outputted_split_files}-{i+1}.wav")
         
     | 
| 193 | 
         
            +
                    for f in sorted(glob.glob("*.wav")):
         
     | 
| 194 | 
         
            +
                        audio_files = glob.glob("*.wav")
         
     | 
| 195 | 
         
            +
                        zip_file_name = "audio_files.zip"
         
     | 
| 196 | 
         
            +
                        with zipfile.ZipFile(zip_file_name, 'w') as zip_file:
         
     | 
| 197 | 
         
            +
                            for audio_file in audio_files:
         
     | 
| 198 | 
         
            +
                                zip_file.write(audio_file, os.path.basename(audio_file))
         
     | 
| 199 | 
         
            +
                    for file2 in glob.glob("*.wav"):
         
     | 
| 200 | 
         
            +
                        os.remove(file2)
         
     | 
| 201 | 
         
            +
                    progress(1, "Done! Cleaning up...")
         
     | 
| 202 | 
         
            +
                    time.sleep(2)
         
     | 
| 203 | 
         
            +
                    return "Process done successfully! Check below for zipped files!", zip_file_name
         
     | 
| 204 | 
         
            +
             
     | 
| 205 | 
         
             
            with gr.Blocks(theme='NoCrypt/miku', title="Global Dataset Maker") as app:
         
     | 
| 206 | 
         
             
                gr.HTML(
         
     | 
| 207 | 
         
             
                    "<h1> Welcome to the GDMGS! (GlobalDatasetMaker Gradio Space) </h1>"
         
     | 
| 
         | 
|
| 278 | 
         
             
                                    [upload],
         
     | 
| 279 | 
         
             
                                    [gr.Text(label="Result")]
         
     | 
| 280 | 
         
             
                                )
         
     | 
| 281 | 
         
            +
                        with gr.Tab("All-in-one downloader and splitter"):
         
     | 
| 282 | 
         
            +
                            gr.Markdown("This is very experimental and may break or change in the future. This essentially combines both the first 2 tabs into an all-in-one script.")
         
     | 
| 283 | 
         
            +
                            with gr.Row():
         
     | 
| 284 | 
         
            +
                                with gr.Column():
         
     | 
| 285 | 
         
            +
                                    with gr.Row():
         
     | 
| 286 | 
         
            +
                                        ytvideo = gr.Textbox(label="URL")
         
     | 
| 287 | 
         
            +
                                        download_yt_video_as = gr.Radio(["wav", "mp3"], value="wav", label="Audio output format")
         
     | 
| 288 | 
         
            +
                                        min_duration = gr.Number(label="Min duration", minimum=1, maximum=10, value=1)
         
     | 
| 289 | 
         
            +
                                        max_duration = gr.Number(label="Max duration", minimum=1, maximum=10, value=5)
         
     | 
| 290 | 
         
            +
                                        name_for_outputted_split_files = gr.Textbox(label="Name for split files")
         
     | 
| 291 | 
         
            +
                                        download_and_split_btn = gr.Button("Download and split", variant='primary')
         
     | 
| 292 | 
         
            +
                                    download_and_split_btn.click(
         
     | 
| 293 | 
         
            +
                                        all_in_one_inator,
         
     | 
| 294 | 
         
            +
                                        [ytvideo, download_yt_video_as, min_duration, max_duration, name_for_outputted_split_files],
         
     | 
| 295 | 
         
            +
                                        [gr.Text(label="Result"), gr.File(label="Zipped files")]
         
     | 
| 296 | 
         
            +
                                    )
         
     | 
| 297 | 
         
             
                    with gr.TabItem("Changelog"):
         
     | 
| 298 | 
         
            +
                        gr.Markdown("v0.92 - Added all-in-one tab under Misc Tools.")
         
     | 
| 299 | 
         
             
                        gr.Markdown("v0.91 - Added mp3 file support for single file splitting, and also fixed bug if neither output.wav or output.mp3 exists.")
         
     | 
| 300 | 
         
             
                        gr.Markdown("v0.90a - Fixed bug that if 'show_amount_of_files_and_file_dur' was False, split wav files would not be deleted.")
         
     | 
| 301 | 
         
             
                        gr.Markdown("v0.90 - Added mp3 support for downloading a Youtube video.")
         
     |