Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,6 +51,7 @@ import os
|
|
| 51 |
import gradio as gr
|
| 52 |
from moviepy.editor import VideoFileClip
|
| 53 |
from datetime import datetime
|
|
|
|
| 54 |
|
| 55 |
def convert_mp4_to_mp3(video_file_path, output_dir):
|
| 56 |
# MP3 λ³ν κ³Όμ
|
|
@@ -76,10 +77,14 @@ def mp4_to_mp3_converter(video_file):
|
|
| 76 |
save_path = os.path.join("/home/user/app", modeltarget)
|
| 77 |
os.makedirs(save_path, exist_ok=True)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
| 79 |
# MP3 λ³ν ν νμΌ κ²½λ‘ λ°ν
|
| 80 |
try:
|
|
|
|
| 81 |
mp3_file_path = convert_mp4_to_mp3(video_file.name, save_path)
|
| 82 |
-
return mp3_file_path # λ€μ΄λ‘λλ₯Ό μν νμΌ κ²½λ‘ λ°ν
|
| 83 |
except Exception as e:
|
| 84 |
return f"Error occurred during conversion: {str(e)}"
|
| 85 |
|
|
@@ -87,20 +92,11 @@ def mp4_to_mp3_converter(video_file):
|
|
| 87 |
iface = gr.Interface(
|
| 88 |
fn=mp4_to_mp3_converter,
|
| 89 |
inputs=gr.File(label="λΉλμ€ νμΌ μ
λ‘λ"),
|
| 90 |
-
outputs=gr.File(label="λ€μ΄λ‘λ MP3"),
|
| 91 |
title="MP4μμ MP3λ‘ λ³νκΈ°",
|
| 92 |
description="λΉλμ€ νμΌμ μ
λ‘λνμ¬ MP3 νμμΌλ‘ λ³νν©λλ€. μ
λ‘λ μκ°μ μ½μμ νμλ©λλ€.",
|
| 93 |
allow_flagging=False,
|
| 94 |
)
|
| 95 |
|
| 96 |
-
# JavaScript μ½λ μ§μ μ½μ
|
| 97 |
-
iface.load_js("""
|
| 98 |
-
function showAlert() {
|
| 99 |
-
alert("μ
λ‘λ μ€μ
λλ€. μ μλ§ κΈ°λ€λ €μ£ΌμΈμ.");
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
document.querySelector("input[type='file']").addEventListener("change", showAlert);
|
| 103 |
-
""")
|
| 104 |
-
|
| 105 |
if __name__ == "__main__":
|
| 106 |
iface.launch()
|
|
|
|
| 51 |
import gradio as gr
|
| 52 |
from moviepy.editor import VideoFileClip
|
| 53 |
from datetime import datetime
|
| 54 |
+
import time
|
| 55 |
|
| 56 |
def convert_mp4_to_mp3(video_file_path, output_dir):
|
| 57 |
# MP3 λ³ν κ³Όμ
|
|
|
|
| 77 |
save_path = os.path.join("/home/user/app", modeltarget)
|
| 78 |
os.makedirs(save_path, exist_ok=True)
|
| 79 |
|
| 80 |
+
# μ¬μ©μμκ² μ
λ‘λ μ€ λ©μμ§ λ°ν
|
| 81 |
+
upload_message = "μ
λ‘λμ€μ
λλ€. μ μλ§ κΈ°λ€λ €μ£ΌμΈμ."
|
| 82 |
+
|
| 83 |
# MP3 λ³ν ν νμΌ κ²½λ‘ λ°ν
|
| 84 |
try:
|
| 85 |
+
time.sleep(1) # μ μ λκΈ°
|
| 86 |
mp3_file_path = convert_mp4_to_mp3(video_file.name, save_path)
|
| 87 |
+
return upload_message, mp3_file_path # λ€μ΄λ‘λλ₯Ό μν νμΌ κ²½λ‘ λ°ν
|
| 88 |
except Exception as e:
|
| 89 |
return f"Error occurred during conversion: {str(e)}"
|
| 90 |
|
|
|
|
| 92 |
iface = gr.Interface(
|
| 93 |
fn=mp4_to_mp3_converter,
|
| 94 |
inputs=gr.File(label="λΉλμ€ νμΌ μ
λ‘λ"),
|
| 95 |
+
outputs=[gr.Markdown(), gr.File(label="λ€μ΄λ‘λ MP3")], # μν λ©μμ§μ λ€μ΄λ‘λ κ°λ₯ν νμΌ μΆλ ₯
|
| 96 |
title="MP4μμ MP3λ‘ λ³νκΈ°",
|
| 97 |
description="λΉλμ€ νμΌμ μ
λ‘λνμ¬ MP3 νμμΌλ‘ λ³νν©λλ€. μ
λ‘λ μκ°μ μ½μμ νμλ©λλ€.",
|
| 98 |
allow_flagging=False,
|
| 99 |
)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
if __name__ == "__main__":
|
| 102 |
iface.launch()
|