danilotpnta commited on
Commit
b444720
·
1 Parent(s): 8f2a13c
Files changed (2) hide show
  1. app.py +10 -10
  2. download_video.py +2 -1
app.py CHANGED
@@ -10,13 +10,13 @@ from download_video import download_mp3_selenium
10
  # Function to download the audio, title, and thumbnail from YouTube
11
  def download_video_info(url):
12
  try:
13
- # Call the function to download video and get title and thumbnail
14
- title, thumbnail_url = download_mp3_selenium(url)
15
  audio_file = "downloaded_video.mp4" # Path to the downloaded audio (MP4)
16
 
17
- return audio_file, title, thumbnail_url
18
  except Exception as e:
19
- return None, None, str(e)
20
 
21
  # Function to transcribe the downloaded audio using Whisper
22
  def transcribe_audio(audio_path, model_size="base"):
@@ -24,14 +24,14 @@ def transcribe_audio(audio_path, model_size="base"):
24
  result = model.transcribe(audio_path)
25
  return result['text']
26
 
27
- # Split logic: First fetch title and thumbnail, then transcribe
28
  def get_video_info_and_transcribe(youtube_url, model_size="base"):
29
- # Fetch title and thumbnail first
30
- audio_path, title, thumbnail_url = download_video_info(youtube_url)
31
 
32
  # If fetching video info fails
33
  if not audio_path or not os.path.exists(audio_path):
34
- return gr.update(value=f"Error fetching video: {thumbnail_url}"), None, None, None
35
 
36
  # Show title and thumbnail to the user while the transcription is happening
37
  title_output = gr.update(value=title)
@@ -45,7 +45,7 @@ def get_video_info_and_transcribe(youtube_url, model_size="base"):
45
  # Start transcription
46
  transcription = transcribe_audio(audio_path, model_size)
47
 
48
- return title_output, thumbnail_output, gr.update(value=transcription)
49
 
50
  # Gradio interface setup using gradio.components
51
  with gr.Blocks() as interface:
@@ -59,7 +59,7 @@ with gr.Blocks() as interface:
59
  thumbnail_output = gr.Image(label="Thumbnail", interactive=False, scale=1)
60
  transcription_output = gr.Textbox(label="Transcription", interactive=False, scale=1)
61
 
62
- logs_output = gr.Textbox(label="ChromeDriver Logs")
63
 
64
  transcribe_button = gr.Button("Transcribe")
65
 
 
10
  # Function to download the audio, title, and thumbnail from YouTube
11
  def download_video_info(url):
12
  try:
13
+ # Call the function to download video and get title, thumbnail, and logs
14
+ title, thumbnail_url, logs_output = download_mp3_selenium(url)
15
  audio_file = "downloaded_video.mp4" # Path to the downloaded audio (MP4)
16
 
17
+ return audio_file, title, thumbnail_url, logs_output
18
  except Exception as e:
19
+ return None, None, None, str(e)
20
 
21
  # Function to transcribe the downloaded audio using Whisper
22
  def transcribe_audio(audio_path, model_size="base"):
 
24
  result = model.transcribe(audio_path)
25
  return result['text']
26
 
27
+ # Split logic: First fetch title, thumbnail, and logs, then transcribe
28
  def get_video_info_and_transcribe(youtube_url, model_size="base"):
29
+ # Fetch title, thumbnail, and logs first
30
+ audio_path, title, thumbnail_url, logs_output = download_video_info(youtube_url)
31
 
32
  # If fetching video info fails
33
  if not audio_path or not os.path.exists(audio_path):
34
+ return gr.update(value=f"Error fetching video: {thumbnail_url}"), None, None, gr.update(value=logs_output)
35
 
36
  # Show title and thumbnail to the user while the transcription is happening
37
  title_output = gr.update(value=title)
 
45
  # Start transcription
46
  transcription = transcribe_audio(audio_path, model_size)
47
 
48
+ return title_output, thumbnail_output, gr.update(value=transcription), gr.update(value=logs_output)
49
 
50
  # Gradio interface setup using gradio.components
51
  with gr.Blocks() as interface:
 
59
  thumbnail_output = gr.Image(label="Thumbnail", interactive=False, scale=1)
60
  transcription_output = gr.Textbox(label="Transcription", interactive=False, scale=1)
61
 
62
+ logs_output = gr.Textbox(label="ChromeDriver Logs", interactive=False)
63
 
64
  transcribe_button = gr.Button("Transcribe")
65
 
download_video.py CHANGED
@@ -9,7 +9,7 @@ import requests
9
  def download_mp3_selenium(youtube_url):
10
  # Set up the Selenium WebDriver
11
  options = webdriver.ChromeOptions()
12
- # options.add_argument("--headless")
13
  options.add_argument("--no-sandbox")
14
  options.add_argument('--disable-dev-shm-usage')
15
  options.add_argument('--disable-gpu') # Disable GPU to ensure it runs in cloud environments
@@ -18,6 +18,7 @@ def download_mp3_selenium(youtube_url):
18
  options.add_argument("--window-size=1920x1080")
19
  options.add_argument("--start-maximized")
20
 
 
21
  driver = webdriver.Chrome(options=options)
22
 
23
  try:
 
9
  def download_mp3_selenium(youtube_url):
10
  # Set up the Selenium WebDriver
11
  options = webdriver.ChromeOptions()
12
+ options.add_argument("--headless")
13
  options.add_argument("--no-sandbox")
14
  options.add_argument('--disable-dev-shm-usage')
15
  options.add_argument('--disable-gpu') # Disable GPU to ensure it runs in cloud environments
 
18
  options.add_argument("--window-size=1920x1080")
19
  options.add_argument("--start-maximized")
20
 
21
+ log_contents = "" # Initialize log_contents
22
  driver = webdriver.Chrome(options=options)
23
 
24
  try: