Jeril commited on
Commit
c7d08a1
1 Parent(s): 6d3a93e

first commit

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import ffmpeg
3
+
4
+
5
+ def extract_audio_from_video(video, start_time, end_time, use_time_cutting):
6
+ input_file = video
7
+ output_file = "media/extracted_audio.mp3"
8
+
9
+ if use_time_cutting:
10
+ ffmpeg.input(input_file, ss=start_time, to=end_time).output(
11
+ output_file, format="mp3"
12
+ ).run(overwrite_output=True)
13
+ else:
14
+ ffmpeg.input(input_file).output(output_file, format="mp3").run(
15
+ overwrite_output=True
16
+ )
17
+
18
+ return output_file
19
+
20
+
21
+ with gr.Blocks() as demo:
22
+ gr.Markdown("<center><h1> Extract Audio </h1></center><br>")
23
+
24
+ with gr.Row():
25
+ video_input = gr.Video(label="Upload Video")
26
+ audio_output = gr.Audio(label="Extracted Audio", type="filepath")
27
+
28
+ with gr.Row():
29
+ start_time_input = gr.Number(label="Start Time (seconds)", value=0, precision=0)
30
+ end_time_input = gr.Number(label="End Time (seconds)", value=10, precision=0)
31
+ use_time_cutting_input = gr.Checkbox(
32
+ label="Use Time-Based Cutting", value=False
33
+ )
34
+
35
+ extract_button = gr.Button("Extract Audio", variant="primary")
36
+
37
+ extract_button.click(
38
+ fn=extract_audio_from_video,
39
+ inputs=[video_input, start_time_input, end_time_input, use_time_cutting_input],
40
+ outputs=audio_output,
41
+ )
42
+
43
+ demo.launch()