jpjp9292 commited on
Commit
fbd53b0
·
verified ·
1 Parent(s): 77d00c8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from moviepy.editor import VideoFileClip
4
+
5
+ def convert_mp4_to_mp3(video_file_path, output_dir):
6
+ video = VideoFileClip(video_file_path)
7
+ audio = video.audio
8
+ output_path = os.path.join(output_dir, os.path.splitext(os.path.basename(video_file_path))[0] + ".mp3")
9
+ audio.write_audiofile(output_path)
10
+ audio.close()
11
+ video.close()
12
+ return output_path
13
+
14
+ def mp4_to_mp3_converter(video_file_path):
15
+ modeltarget = "mp4_to_mp3_conversion"
16
+ save_path = os.path.join("/home/user/app", modeltarget)
17
+ os.makedirs(save_path, exist_ok=True)
18
+ mp3_file_path = convert_mp4_to_mp3(video_file_path, save_path)
19
+ return mp3_file_path
20
+
21
+ iface = gr.Interface(
22
+ fn=mp4_to_mp3_converter,
23
+ inputs=gr.inputs.File(label="Input Video", type="file"),
24
+ outputs=gr.outputs.File(label="Output Audio", type="file"),
25
+ title="MP4 to MP3 Converter",
26
+ description="Upload a video file to convert it to MP3 format."
27
+ )
28
+
29
+ if __name__ == "__main__":
30
+ iface.launch(server_name="0.0.0.0", server_port=7860)