jpjp9292 commited on
Commit
d03632e
Β·
verified Β·
1 Parent(s): e1a2cb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import time
4
  from moviepy.editor import VideoFileClip
5
  from faster_whisper import WhisperModel
 
6
 
7
  # λΉ„λ””μ˜€λ₯Ό MP3둜 λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜
8
  def convert_mp4_to_mp3(video_file_path, output_dir):
@@ -38,10 +39,17 @@ def transcribe_audio(model_size, audio_file):
38
 
39
  return f"{detected_language}\n\nTranscription:\n{result_text}\n\nElapsed time: {elapsed_time:.2f} seconds"
40
 
 
 
 
 
 
 
 
41
  # Gradio μΈν„°νŽ˜μ΄μŠ€μ—μ„œ μ‚¬μš©ν•  메인 ν•¨μˆ˜
42
  def process_video(model_size, video_file=None, video_url=None):
43
  if video_url and not video_file:
44
- video_file_path = gr.processing_utils.download_url(video_url, dir='/tmp')
45
  elif video_file and not video_url:
46
  video_file_path = video_file.name
47
  else:
 
3
  import time
4
  from moviepy.editor import VideoFileClip
5
  from faster_whisper import WhisperModel
6
+ from pytube import YouTube
7
 
8
  # λΉ„λ””μ˜€λ₯Ό MP3둜 λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜
9
  def convert_mp4_to_mp3(video_file_path, output_dir):
 
39
 
40
  return f"{detected_language}\n\nTranscription:\n{result_text}\n\nElapsed time: {elapsed_time:.2f} seconds"
41
 
42
+ # YouTube URLμ—μ„œ λΉ„λ””μ˜€λ₯Ό λ‹€μš΄λ‘œλ“œν•˜λŠ” ν•¨μˆ˜
43
+ def download_youtube_video(url, output_dir):
44
+ yt = YouTube(url)
45
+ stream = yt.streams.filter(file_extension='mp4').first()
46
+ output_path = stream.download(output_dir)
47
+ return output_path
48
+
49
  # Gradio μΈν„°νŽ˜μ΄μŠ€μ—μ„œ μ‚¬μš©ν•  메인 ν•¨μˆ˜
50
  def process_video(model_size, video_file=None, video_url=None):
51
  if video_url and not video_file:
52
+ video_file_path = download_youtube_video(video_url, '/tmp')
53
  elif video_file and not video_url:
54
  video_file_path = video_file.name
55
  else: