Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import gradio as gr, glob, os, auditok, zipfile, requests, json, traceback, tempfile
|
| 2 |
from moviepy.editor import *
|
| 3 |
from pydub import AudioSegment
|
| 4 |
|
|
@@ -41,11 +41,13 @@ def mp4_to_wav_or_mp3(mp4fileuploader, file_format):
|
|
| 41 |
try:
|
| 42 |
if file_format == "wav":
|
| 43 |
videoinput = AudioFileClip(mp4fileuploader)
|
| 44 |
-
|
|
|
|
| 45 |
videoinput.close()
|
| 46 |
elif file_format == "mp3":
|
| 47 |
videoinput = AudioFileClip(mp4fileuploader)
|
| 48 |
-
|
|
|
|
| 49 |
videoinput.close()
|
| 50 |
what_to_return = "convertedaudio.wav" if file_format == "wav" else "convertedaudio.mp3"
|
| 51 |
os.remove(mp4fileuploader)
|
|
@@ -203,11 +205,12 @@ with gr.Blocks(theme='bethecloud/storj_theme', title="Global Dataset Maker") as
|
|
| 203 |
with gr.Row():
|
| 204 |
mp4fileuploader = gr.File(file_count='single', file_types=[".mp4"], label="mp4 file")
|
| 205 |
file_format = gr.Radio(["wav", "mp3"], value="mp3", label="Convert mp4 file to:")
|
|
|
|
| 206 |
convert_btn = gr.Button("Convert", variant='primary')
|
| 207 |
remove_file_btn = gr.Button("Remove file from directory", variant='secondary')
|
| 208 |
convert_btn.click(
|
| 209 |
mp4_to_wav_or_mp3,
|
| 210 |
-
[mp4fileuploader, file_format],
|
| 211 |
[gr.Text(label="Output"), gr.File(label="Converted audio file")]
|
| 212 |
)
|
| 213 |
remove_file_btn.click(
|
|
@@ -314,6 +317,7 @@ with gr.Blocks(theme='bethecloud/storj_theme', title="Global Dataset Maker") as
|
|
| 314 |
)
|
| 315 |
|
| 316 |
with gr.TabItem("Changelog"):
|
|
|
|
| 317 |
gr.Markdown("v1.1 - Added new tool: Convert many audio files to one file.")
|
| 318 |
gr.Markdown("v1 - Not the most exciting v1 release. **Removed yt functions as they are no longer working.**")
|
| 319 |
gr.Markdown("v0.99.9 - Added new tool: Split audio file by duration.")
|
|
|
|
| 1 |
+
import gradio as gr, glob, os, auditok, zipfile, requests, json, traceback, tempfile, random
|
| 2 |
from moviepy.editor import *
|
| 3 |
from pydub import AudioSegment
|
| 4 |
|
|
|
|
| 41 |
try:
|
| 42 |
if file_format == "wav":
|
| 43 |
videoinput = AudioFileClip(mp4fileuploader)
|
| 44 |
+
output_filename = "convertedaudio.wav" if not random_filename else f"convertedaudio_{random.randint(1000, 9999)}.wav"
|
| 45 |
+
videoinput.write_audiofile(output_filename)
|
| 46 |
videoinput.close()
|
| 47 |
elif file_format == "mp3":
|
| 48 |
videoinput = AudioFileClip(mp4fileuploader)
|
| 49 |
+
output_filename = "convertedaudio.mp3" if not random_filename else f"convertedaudio_{random.randint(1000, 9999)}.mp3"
|
| 50 |
+
videoinput.write_audiofile(output_filename)
|
| 51 |
videoinput.close()
|
| 52 |
what_to_return = "convertedaudio.wav" if file_format == "wav" else "convertedaudio.mp3"
|
| 53 |
os.remove(mp4fileuploader)
|
|
|
|
| 205 |
with gr.Row():
|
| 206 |
mp4fileuploader = gr.File(file_count='single', file_types=[".mp4"], label="mp4 file")
|
| 207 |
file_format = gr.Radio(["wav", "mp3"], value="mp3", label="Convert mp4 file to:")
|
| 208 |
+
random_filename = gr.Checkbox(False, label="Use random filename?")
|
| 209 |
convert_btn = gr.Button("Convert", variant='primary')
|
| 210 |
remove_file_btn = gr.Button("Remove file from directory", variant='secondary')
|
| 211 |
convert_btn.click(
|
| 212 |
mp4_to_wav_or_mp3,
|
| 213 |
+
[mp4fileuploader, file_format, random_filename],
|
| 214 |
[gr.Text(label="Output"), gr.File(label="Converted audio file")]
|
| 215 |
)
|
| 216 |
remove_file_btn.click(
|
|
|
|
| 317 |
)
|
| 318 |
|
| 319 |
with gr.TabItem("Changelog"):
|
| 320 |
+
gr.Markdown("v1.2 - Added an option (in mp4 to mp3/wav converter) to have the output file be a random filename.")
|
| 321 |
gr.Markdown("v1.1 - Added new tool: Convert many audio files to one file.")
|
| 322 |
gr.Markdown("v1 - Not the most exciting v1 release. **Removed yt functions as they are no longer working.**")
|
| 323 |
gr.Markdown("v0.99.9 - Added new tool: Split audio file by duration.")
|