Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ def sanitize_filename(filename):
|
|
19 |
|
20 |
def convert_audio(audio_file, target_format):
|
21 |
try:
|
|
|
|
|
|
|
22 |
# Membuat direktori sementara untuk file yang diunggah
|
23 |
temp_dir = tempfile.mkdtemp()
|
24 |
|
@@ -34,14 +37,18 @@ def convert_audio(audio_file, target_format):
|
|
34 |
ffmpeg.input(audio_path).output(output_file).run() # Mengonversi audio ke format yang diinginkan
|
35 |
|
36 |
return output_file
|
|
|
|
|
|
|
37 |
except Exception as e:
|
|
|
38 |
return f"Error: {e}"
|
39 |
|
40 |
# Antarmuka Gradio dengan tema kustom untuk menyembunyikan footer
|
41 |
interface = gr.Interface(
|
42 |
fn=convert_audio,
|
43 |
inputs=[
|
44 |
-
gr.File(label="Upload Audio File", type="
|
45 |
gr.Dropdown(label="Select Target Format", choices=audio_formats)
|
46 |
],
|
47 |
outputs=gr.File(label="Converted Audio File"),
|
|
|
19 |
|
20 |
def convert_audio(audio_file, target_format):
|
21 |
try:
|
22 |
+
# Pastikan ffmpeg sudah terinstal
|
23 |
+
ffmpeg.probe(audio_file) # Cek keberadaan ffmpeg dan file yang valid
|
24 |
+
|
25 |
# Membuat direktori sementara untuk file yang diunggah
|
26 |
temp_dir = tempfile.mkdtemp()
|
27 |
|
|
|
37 |
ffmpeg.input(audio_path).output(output_file).run() # Mengonversi audio ke format yang diinginkan
|
38 |
|
39 |
return output_file
|
40 |
+
except ffmpeg.Error as e:
|
41 |
+
# Tangkap kesalahan ffmpeg dan tampilkan pesan error lebih rinci
|
42 |
+
return f"FFMPEG Error: {e.stderr.decode()}"
|
43 |
except Exception as e:
|
44 |
+
# Tangkap kesalahan lain dan tampilkan pesan error lebih rinci
|
45 |
return f"Error: {e}"
|
46 |
|
47 |
# Antarmuka Gradio dengan tema kustom untuk menyembunyikan footer
|
48 |
interface = gr.Interface(
|
49 |
fn=convert_audio,
|
50 |
inputs=[
|
51 |
+
gr.File(label="Upload Audio File", type="filepath", file_types=[".mp3", ".wav", ".aac", ".flac", ".ogg", ".m4a", ".alac", ".wma", ".aiff", ".opus", ".ape", ".caf", ".pcm", ".dts", ".tta", ".amr", ".mid", ".spx", ".wv", ".ra", ".tak"]),
|
52 |
gr.Dropdown(label="Select Target Format", choices=audio_formats)
|
53 |
],
|
54 |
outputs=gr.File(label="Converted Audio File"),
|