Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -63,37 +63,64 @@ def convert_mp4_to_mp3(video_file_path, output_dir):
|
|
63 |
video.close()
|
64 |
return output_path
|
65 |
|
66 |
-
def mp4_to_mp3_converter(video_file):
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
# λΉλμ€ νμΌμ΄ μμ λ μ²λ¦¬
|
72 |
if video_file is None:
|
73 |
return "Error: No video file was uploaded."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# μ μ₯ κ²½λ‘ μ€μ
|
76 |
modeltarget = "mp4_to_mp3_conversion"
|
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
|
88 |
except Exception as e:
|
89 |
return f"Error occurred during conversion: {str(e)}"
|
90 |
|
|
|
|
|
|
|
91 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
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="
|
97 |
description="λΉλμ€ νμΌμ μ
λ‘λνμ¬ MP3 νμμΌλ‘ λ³νν©λλ€. μ
λ‘λ μκ°μ μ½μμ νμλ©λλ€.",
|
98 |
allow_flagging=False,
|
99 |
)
|
|
|
63 |
video.close()
|
64 |
return output_path
|
65 |
|
66 |
+
# def mp4_to_mp3_converter(video_file):
|
67 |
+
# # μ
λ‘λ μκ° νμ
|
68 |
+
# upload_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
69 |
+
# print(f"File uploaded at: {upload_time}")
|
70 |
+
|
71 |
+
# # λΉλμ€ νμΌμ΄ μμ λ μ²λ¦¬
|
72 |
+
# if video_file is None:
|
73 |
+
# return "Error: No video file was uploaded."
|
74 |
+
|
75 |
+
# # μ μ₯ κ²½λ‘ μ€μ
|
76 |
+
# modeltarget = "mp4_to_mp3_conversion"
|
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 |
+
|
91 |
+
def mp4_to_mp3_converter(video_file):
|
92 |
# λΉλμ€ νμΌμ΄ μμ λ μ²λ¦¬
|
93 |
if video_file is None:
|
94 |
return "Error: No video file was uploaded."
|
95 |
+
|
96 |
+
# νμΌ νμ₯μ 체ν¬
|
97 |
+
allowed_extensions = ['mp4', 'webm', 'avi', 'mov', 'mkv']
|
98 |
+
file_extension = os.path.splitext(video_file.name)[1][1:].lower()
|
99 |
+
|
100 |
+
if file_extension not in allowed_extensions:
|
101 |
+
return f"Error: Unsupported file format. Please upload a file with one of the following extensions: {', '.join(allowed_extensions)}"
|
102 |
|
103 |
# μ μ₯ κ²½λ‘ μ€μ
|
104 |
modeltarget = "mp4_to_mp3_conversion"
|
105 |
save_path = os.path.join("/home/user/app", modeltarget)
|
106 |
os.makedirs(save_path, exist_ok=True)
|
107 |
|
|
|
|
|
|
|
108 |
# MP3 λ³ν ν νμΌ κ²½λ‘ λ°ν
|
109 |
try:
|
|
|
110 |
mp3_file_path = convert_mp4_to_mp3(video_file.name, save_path)
|
111 |
+
return mp3_file_path # λ€μ΄λ‘λλ₯Ό μν νμΌ κ²½λ‘ λ°ν
|
112 |
except Exception as e:
|
113 |
return f"Error occurred during conversion: {str(e)}"
|
114 |
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
119 |
iface = gr.Interface(
|
120 |
fn=mp4_to_mp3_converter,
|
121 |
inputs=gr.File(label="λΉλμ€ νμΌ μ
λ‘λ"),
|
122 |
outputs=[gr.Markdown(), gr.File(label="λ€μ΄λ‘λ MP3")], # μν λ©μμ§μ λ€μ΄λ‘λ κ°λ₯ν νμΌ μΆλ ₯
|
123 |
+
title="λΉλμ€μμ μμ± νμΌλ‘ λ³νκΈ°",
|
124 |
description="λΉλμ€ νμΌμ μ
λ‘λνμ¬ MP3 νμμΌλ‘ λ³νν©λλ€. μ
λ‘λ μκ°μ μ½μμ νμλ©λλ€.",
|
125 |
allow_flagging=False,
|
126 |
)
|