AmnaHassan commited on
Commit
75ec559
·
verified ·
1 Parent(s): be1e76c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  from pytube import YouTube
4
  from crewai import Agent, Task, Crew
@@ -6,6 +5,7 @@ from transformers import pipeline
6
  import torch
7
  import whisper
8
  import yt_dlp
 
9
 
10
  st.title("AI Blog Writer from YouTube")
11
 
@@ -13,11 +13,16 @@ st.title("AI Blog Writer from YouTube")
13
  whisper_model = whisper.load_model("base")
14
 
15
  def download_audio(video_url):
16
- """Downloads audio from the YouTube video using yt-dlp."""
 
 
 
17
  ydl_opts = {
18
  'format': 'bestaudio/best',
19
  'outtmpl': 'audio.mp4',
 
20
  }
 
21
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
22
  info_dict = ydl.extract_info(video_url, download=True)
23
  return 'audio.mp4'
@@ -47,7 +52,7 @@ if st.button("Generate Blog"):
47
  if video_url:
48
  try:
49
  st.info("Downloading audio...")
50
- audio_path = download_audio(video_url)
51
  st.success("Audio downloaded successfully!")
52
 
53
  st.info("Transcribing audio using Whisper...")
 
 
1
  import streamlit as st
2
  from pytube import YouTube
3
  from crewai import Agent, Task, Crew
 
5
  import torch
6
  import whisper
7
  import yt_dlp
8
+ import os
9
 
10
  st.title("AI Blog Writer from YouTube")
11
 
 
13
  whisper_model = whisper.load_model("base")
14
 
15
  def download_audio(video_url):
16
+ """Downloads audio from the YouTube video using yt-dlp with cookies."""
17
+ # Get the path to the cookies file from the current directory
18
+ cookies_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cookies.json')
19
+
20
  ydl_opts = {
21
  'format': 'bestaudio/best',
22
  'outtmpl': 'audio.mp4',
23
+ 'cookies': cookies_file, # Path to the cookies file
24
  }
25
+
26
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
27
  info_dict = ydl.extract_info(video_url, download=True)
28
  return 'audio.mp4'
 
52
  if video_url:
53
  try:
54
  st.info("Downloading audio...")
55
+ audio_path = download_audio(video_url) # No need to ask for cookies file path anymore
56
  st.success("Audio downloaded successfully!")
57
 
58
  st.info("Transcribing audio using Whisper...")