pere commited on
Commit
add94c7
·
1 Parent(s): 7630322

update test

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -2,7 +2,7 @@ import time
2
  import os
3
 
4
  import torch
5
-
6
  import gradio as gr
7
  import pytube as pt
8
  import spaces
@@ -66,30 +66,23 @@ def _return_yt_html_embed(yt_url):
66
 
67
 
68
  def yt_transcribe(yt_url, return_timestamps=False):
69
- try:
70
- yt = pt.YouTube(yt_url)
71
- except Exception as e:
72
- return f"Error fetching YouTube video: {str(e)}"
73
-
74
- html_embed_str = _return_yt_html_embed(yt_url)
75
-
76
- audio_streams = yt.streams.filter(only_audio=True)
77
- if not audio_streams:
78
- return "No audio streams available for this video."
79
-
80
- stream = audio_streams[0]
81
 
82
  try:
83
- stream.download(filename="audio.mp3")
 
84
  except Exception as e:
85
  return f"Error downloading audio: {str(e)}"
86
-
87
  if not os.path.exists("audio.mp3"):
88
  return "Downloaded audio file not found."
89
 
90
  text = transcribe("audio.mp3", return_timestamps=return_timestamps)
91
-
92
- return html_embed_str, text
93
 
94
 
95
  demo = gr.Blocks()
 
2
  import os
3
 
4
  import torch
5
+ import yt_dlp
6
  import gradio as gr
7
  import pytube as pt
8
  import spaces
 
66
 
67
 
68
  def yt_transcribe(yt_url, return_timestamps=False):
69
+ ydl_opts = {
70
+ 'format': 'bestaudio/best',
71
+ 'outtmpl': 'audio.mp3',
72
+ 'noplaylist': True
73
+ }
 
 
 
 
 
 
 
74
 
75
  try:
76
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
77
+ ydl.download([yt_url])
78
  except Exception as e:
79
  return f"Error downloading audio: {str(e)}"
80
+
81
  if not os.path.exists("audio.mp3"):
82
  return "Downloaded audio file not found."
83
 
84
  text = transcribe("audio.mp3", return_timestamps=return_timestamps)
85
+ return _return_yt_html_embed(yt_url), text
 
86
 
87
 
88
  demo = gr.Blocks()