jpjp9292 commited on
Commit
4bace7d
Β·
verified Β·
1 Parent(s): b0c6a14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
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()