File size: 640 Bytes
22bdbd6
 
 
 
 
660be62
 
 
 
 
 
 
 
 
22bdbd6
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
import ffmpeg

def convert_to_mp3(file):
    input_file = file.name
    output_file = "output.mp3"
    
    # Use ffmpeg to extract audio and convert it to mp3
    try:
        ffmpeg.input(input_file).output(output_file).run(overwrite_output=True)
    except FileNotFoundError as e:
        return str(e)
    
    return output_file

app = gr.Interface(
    fn=convert_to_mp3,
    inputs=gr.File(label="Upload Audio/Video File"),
    outputs=gr.File(label="Download MP3 File"),
    title="Convert Audio/Video to MP3",
    description="Upload an audio or video file and convert its audio to MP3 format."
)

app.launch()