Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from moviepy.editor import VideoFileClip
|
@@ -37,11 +86,21 @@ def mp4_to_mp3_converter(video_file):
|
|
37 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
38 |
iface = gr.Interface(
|
39 |
fn=mp4_to_mp3_converter,
|
40 |
-
inputs=gr.File(label="
|
41 |
-
outputs=gr.File(label="
|
42 |
-
title="MP4
|
43 |
-
description="
|
|
|
44 |
)
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
if __name__ == "__main__":
|
47 |
iface.launch()
|
|
|
1 |
+
# import os
|
2 |
+
# import gradio as gr
|
3 |
+
# from moviepy.editor import VideoFileClip
|
4 |
+
# from datetime import datetime
|
5 |
+
|
6 |
+
# def convert_mp4_to_mp3(video_file_path, output_dir):
|
7 |
+
# # MP3 λ³ν κ³Όμ
|
8 |
+
# video = VideoFileClip(video_file_path)
|
9 |
+
# audio = video.audio
|
10 |
+
# output_path = os.path.join(output_dir, os.path.splitext(os.path.basename(video_file_path))[0] + ".mp3")
|
11 |
+
# audio.write_audiofile(output_path)
|
12 |
+
# audio.close()
|
13 |
+
# video.close()
|
14 |
+
# return output_path
|
15 |
+
|
16 |
+
# def mp4_to_mp3_converter(video_file):
|
17 |
+
# # μ
λ‘λ μκ° νμ
|
18 |
+
# upload_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
19 |
+
# print(f"File uploaded at: {upload_time}")
|
20 |
+
|
21 |
+
# # λΉλμ€ νμΌμ΄ μμ λ μ²λ¦¬
|
22 |
+
# if video_file is None:
|
23 |
+
# return "Error: No video file was uploaded."
|
24 |
+
|
25 |
+
# # μ μ₯ κ²½λ‘ μ€μ
|
26 |
+
# modeltarget = "mp4_to_mp3_conversion"
|
27 |
+
# save_path = os.path.join("/home/user/app", modeltarget)
|
28 |
+
# os.makedirs(save_path, exist_ok=True)
|
29 |
+
|
30 |
+
# # MP3 λ³ν ν νμΌ κ²½λ‘ λ°ν
|
31 |
+
# try:
|
32 |
+
# mp3_file_path = convert_mp4_to_mp3(video_file.name, save_path)
|
33 |
+
# return mp3_file_path # λ€μ΄λ‘λλ₯Ό μν νμΌ κ²½λ‘ λ°ν
|
34 |
+
# except Exception as e:
|
35 |
+
# return f"Error occurred during conversion: {str(e)}"
|
36 |
+
|
37 |
+
# # Gradio μΈν°νμ΄μ€ μ€μ
|
38 |
+
# iface = gr.Interface(
|
39 |
+
# fn=mp4_to_mp3_converter,
|
40 |
+
# inputs=gr.File(label="Input Video"),
|
41 |
+
# outputs=gr.File(label="Download MP3"), # λ€μ΄λ‘λ κ°λ₯ν νμΌ μΆλ ₯
|
42 |
+
# title="MP4 to MP3 Converter",
|
43 |
+
# description="Upload a video file to convert it to MP3 format. Upload time will be displayed in the console."
|
44 |
+
# )
|
45 |
+
|
46 |
+
# if __name__ == "__main__":
|
47 |
+
# iface.launch()
|
48 |
+
|
49 |
+
|
50 |
import os
|
51 |
import gradio as gr
|
52 |
from moviepy.editor import VideoFileClip
|
|
|
86 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
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()
|