rafaaa2105 commited on
Commit
72014e7
·
verified ·
1 Parent(s): a24b265

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -7,6 +7,8 @@ import tempfile
7
  import torch
8
  from transformers import WhisperProcessor, WhisperForConditionalGeneration
9
  import spaces
 
 
10
 
11
  def extract_audio(video_path):
12
  video = mp.VideoFileClip(video_path)
@@ -75,19 +77,33 @@ def process_video(video_path, target_language):
75
 
76
  return output_path
77
 
78
- def gradio_interface(video, target_language):
79
- output_video = process_video(video.name, target_language)
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  return output_video
81
 
82
  iface = gr.Interface(
83
  fn=gradio_interface,
84
  inputs=[
85
  gr.Video(label="Upload Video"),
 
86
  gr.Dropdown(choices=["es", "fr", "de", "it", "ja", "ko", "zh-CN"], label="Target Language")
87
  ],
88
  outputs=gr.Video(label="Processed Video"),
89
  title="Video Subtitle Translator",
90
- description="Upload a video, and get it back with translated subtitles!"
91
  )
92
 
93
  iface.launch()
 
7
  import torch
8
  from transformers import WhisperProcessor, WhisperForConditionalGeneration
9
  import spaces
10
+ import pytube
11
+ import librosa
12
 
13
  def extract_audio(video_path):
14
  video = mp.VideoFileClip(video_path)
 
77
 
78
  return output_path
79
 
80
+ def download_youtube_video(youtube_link):
81
+ yt = pytube.YouTube(youtube_link)
82
+ video = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
83
+ video_path = video.download(output_path=tempfile.gettempdir())
84
+ return video_path
85
+
86
+ def gradio_interface(video, yt_link, target_language):
87
+ if video is not None:
88
+ video_path = video.name
89
+ elif yt_link:
90
+ video_path = download_youtube_video(yt_link)
91
+ else:
92
+ raise ValueError("Please provide either a video file or a YouTube link.")
93
+
94
+ output_video = process_video(video_path, target_language)
95
  return output_video
96
 
97
  iface = gr.Interface(
98
  fn=gradio_interface,
99
  inputs=[
100
  gr.Video(label="Upload Video"),
101
+ gr.Textbox(label="YouTube Link"),
102
  gr.Dropdown(choices=["es", "fr", "de", "it", "ja", "ko", "zh-CN"], label="Target Language")
103
  ],
104
  outputs=gr.Video(label="Processed Video"),
105
  title="Video Subtitle Translator",
106
+ description="Upload a video or provide a YouTube link, and get it back with translated subtitles!"
107
  )
108
 
109
  iface.launch()