AmnaHassan commited on
Commit
d4b5cd2
·
verified ·
1 Parent(s): 066cc02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -1,10 +1,8 @@
1
  import streamlit as st
2
- from pytube import YouTube
3
  from crewai import Agent, Task, Crew
4
  from transformers import pipeline
5
  import torch
6
  import whisper
7
- import yt_dlp
8
  import os
9
 
10
  st.title("AI Blog Writer from YouTube")
@@ -12,20 +10,20 @@ st.title("AI Blog Writer from YouTube")
12
  # Whisper model setup (Base Model for better speed)
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 = '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'
 
29
 
30
  def transcribe_audio(audio_path):
31
  """Transcribes the audio using Whisper AI."""
@@ -51,12 +49,8 @@ video_url = st.text_input("Enter YouTube Video URL:")
51
  if st.button("Generate Blog"):
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...")
59
- transcript_text = transcribe_audio(audio_path)
60
  st.text_area("Transcript Extracted", transcript_text, height=200)
61
 
62
  # Generate Blog with CrewAI
 
1
  import streamlit as st
 
2
  from crewai import Agent, Task, Crew
3
  from transformers import pipeline
4
  import torch
5
  import whisper
 
6
  import os
7
 
8
  st.title("AI Blog Writer from YouTube")
 
10
  # Whisper model setup (Base Model for better speed)
11
  whisper_model = whisper.load_model("base")
12
 
13
+ def get_video_transcript(video_url):
14
+ """Fetch video transcript using CrewAI's YouTubeChannelSearch tool."""
15
+ from crewai.tools.youtubechannelsearch import YouTubeChannelSearch
16
+
17
+ # Initialize the YouTube Channel Search tool
18
+ search_tool = YouTubeChannelSearch()
19
+
20
+ # Search for video and fetch transcript
21
+ video_data = search_tool.search(video_url)
 
22
 
23
+ if video_data and 'transcript' in video_data:
24
+ return video_data['transcript']
25
+ else:
26
+ raise Exception("Transcript not found for this video.")
27
 
28
  def transcribe_audio(audio_path):
29
  """Transcribes the audio using Whisper AI."""
 
49
  if st.button("Generate Blog"):
50
  if video_url:
51
  try:
52
+ st.info("Fetching transcript...")
53
+ transcript_text = get_video_transcript(video_url) # Fetch transcript using CrewAI
 
 
 
 
54
  st.text_area("Transcript Extracted", transcript_text, height=200)
55
 
56
  # Generate Blog with CrewAI