Spaces:
Running
Running
File size: 1,955 Bytes
fbd53b0 dc33463 fbd53b0 3db36f3 4bace7d fbd53b0 dc33463 fbd53b0 dc33463 fbd53b0 d579a03 dc33463 7d8a534 d579a03 7d8a534 dc33463 3db36f3 dc33463 7d8a534 dc33463 7d8a534 dc33463 7d8a534 d579a03 dc33463 7241525 7d8a534 d579a03 7241525 b0c6a14 dc33463 fbd53b0 7d8a534 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import os
import gradio as gr
from moviepy.editor import VideoFileClip
from datetime import datetime
import time
def convert_mp4_to_mp3(video_file_path, output_dir):
# MP3 λ³ν κ³Όμ
video = VideoFileClip(video_file_path)
audio = video.audio
output_path = os.path.join(output_dir, os.path.splitext(os.path.basename(video_file_path))[0] + ".mp3")
audio.write_audiofile(output_path)
audio.close()
video.close()
return output_path
def mp4_to_mp3_converter(video_file):
# λΉλμ€ νμΌμ΄ μμ λ μ²λ¦¬
if video_file is None:
return "μ€λ₯: μ
λ‘λλ λΉλμ€ νμΌμ΄ μμ΅λλ€.", None
# νμΌ νμ₯μ 체ν¬
allowed_extensions = ['mp4', 'webm', 'avi', 'mov', 'mkv']
file_extension = os.path.splitext(video_file.name)[1][1:].lower()
if file_extension not in allowed_extensions:
return f"μ€λ₯: μ§μλμ§ μλ νμΌ νμμ
λλ€. λ€μ νμ₯μ μ€ νλμ νμΌμ μ
λ‘λνμΈμ: {', '.join(allowed_extensions)}", None
# μ μ₯ κ²½λ‘ μ€μ
modeltarget = "mp4_to_mp3_conversion"
save_path = os.path.join("/home/user/app", modeltarget)
os.makedirs(save_path, exist_ok=True)
# MP3 λ³ν λ° κ²°κ³Ό λ°ν
try:
mp3_file_path = convert_mp4_to_mp3(video_file.name, save_path)
return f"λ³ν μλ£! MP3 νμΌμ΄ μμ±λμμ΅λλ€.", mp3_file_path
except Exception as e:
return f"λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", None
# Gradio μΈν°νμ΄μ€ μ€μ
iface = gr.Interface(
fn=mp4_to_mp3_converter,
inputs=gr.File(label="λΉλμ€ νμΌ μ
λ‘λ"),
outputs=[
gr.Markdown(label="μν"),
gr.File(label="λ€μ΄λ‘λ MP3")
],
title="λΉλμ€μμ μμ± νμΌλ‘ λ³νκΈ°",
description="λΉλμ€ νμΌμ MP3 νμμΌλ‘ λ³νν©λλ€.",
allow_flagging=False,
)
if __name__ == "__main__":
iface.launch() |