Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -89,14 +89,25 @@ def download_audio_youtube(url, cookies_file=None):
|
|
89 |
try:
|
90 |
temp_dir = tempfile.mkdtemp()
|
91 |
out_path = os.path.join(temp_dir, "audio")
|
92 |
-
|
93 |
'format': 'bestaudio[ext=m4a]/bestaudio/best',
|
94 |
'outtmpl': out_path + '.%(ext)s',
|
95 |
'quiet': True,
|
96 |
'noplaylist': True,
|
97 |
'cookiefile': cookies_file if cookies_file else None,
|
98 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
|
|
99 |
'force_ipv4': True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
}
|
101 |
with YoutubeDL(ydl_opts) as ydl:
|
102 |
ydl.download([url])
|
@@ -113,16 +124,21 @@ def download_audio_youtube(url, cookies_file=None):
|
|
113 |
def full_pipeline(url, cookies):
|
114 |
if not url:
|
115 |
return "β Enter a valid YouTube URL", "", ""
|
116 |
-
|
|
|
|
|
117 |
audio_path, msg = download_audio_youtube(url, temp_cookie)
|
118 |
if not audio_path:
|
119 |
return msg, "", ""
|
|
|
120 |
transcript, tmsg = transcribe_audio(audio_path)
|
121 |
if "β" in transcript:
|
122 |
return msg, transcript, tmsg
|
|
|
123 |
stock_data = extract_stock_info_simple(transcript)
|
124 |
return "β
Complete", transcript, stock_data
|
125 |
|
|
|
126 |
# Gradio App
|
127 |
with gr.Blocks(title="π Stock Info Extractor from YouTube") as demo:
|
128 |
gr.Markdown("""
|
|
|
89 |
try:
|
90 |
temp_dir = tempfile.mkdtemp()
|
91 |
out_path = os.path.join(temp_dir, "audio")
|
92 |
+
ydl_opts = {
|
93 |
'format': 'bestaudio[ext=m4a]/bestaudio/best',
|
94 |
'outtmpl': out_path + '.%(ext)s',
|
95 |
'quiet': True,
|
96 |
'noplaylist': True,
|
97 |
'cookiefile': cookies_file if cookies_file else None,
|
98 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
99 |
+
'referer': 'https://www.youtube.com/',
|
100 |
'force_ipv4': True,
|
101 |
+
'http_headers': {
|
102 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
103 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
104 |
+
'Accept-Language': 'en-US,en;q=0.5',
|
105 |
+
'Accept-Encoding': 'gzip, deflate',
|
106 |
+
'DNT': '1',
|
107 |
+
'Connection': 'keep-alive',
|
108 |
+
'Upgrade-Insecure-Requests': '1',
|
109 |
+
'Referer': 'https://www.youtube.com/',
|
110 |
+
},
|
111 |
}
|
112 |
with YoutubeDL(ydl_opts) as ydl:
|
113 |
ydl.download([url])
|
|
|
124 |
def full_pipeline(url, cookies):
|
125 |
if not url:
|
126 |
return "β Enter a valid YouTube URL", "", ""
|
127 |
+
|
128 |
+
temp_cookie = save_uploaded_cookie(cookies)
|
129 |
+
|
130 |
audio_path, msg = download_audio_youtube(url, temp_cookie)
|
131 |
if not audio_path:
|
132 |
return msg, "", ""
|
133 |
+
|
134 |
transcript, tmsg = transcribe_audio(audio_path)
|
135 |
if "β" in transcript:
|
136 |
return msg, transcript, tmsg
|
137 |
+
|
138 |
stock_data = extract_stock_info_simple(transcript)
|
139 |
return "β
Complete", transcript, stock_data
|
140 |
|
141 |
+
|
142 |
# Gradio App
|
143 |
with gr.Blocks(title="π Stock Info Extractor from YouTube") as demo:
|
144 |
gr.Markdown("""
|