Spaces:
Sleeping
Sleeping
File size: 2,386 Bytes
0281098 03dac85 3a9f730 75ec559 0281098 03dac85 0281098 3a9f730 0281098 d4b5cd2 75ec559 d4b5cd2 3a9f730 0281098 3a9f730 03dac85 3a9f730 03dac85 0281098 03dac85 0281098 03dac85 0281098 3a9f730 03dac85 3a9f730 0281098 d4b5cd2 3a9f730 0281098 03dac85 0281098 03dac85 0281098 3a9f730 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import streamlit as st
from crewai import Agent, Task, Crew
from transformers import pipeline
import torch
import whisper
import os
st.title("AI Blog Writer from YouTube")
# Whisper model setup (Base Model for better speed)
whisper_model = whisper.load_model("base")
def get_video_transcript(video_url):
"""Fetch video transcript using CrewAI's YouTubeChannelSearch tool."""
from crewai.tools.youtubechannelsearch import YouTubeChannelSearch
# Initialize the YouTube Channel Search tool
search_tool = YouTubeChannelSearch()
# Search for video and fetch transcript
video_data = search_tool.search(video_url)
if video_data and 'transcript' in video_data:
return video_data['transcript']
else:
raise Exception("Transcript not found for this video.")
def transcribe_audio(audio_path):
"""Transcribes the audio using Whisper AI."""
transcription = whisper_model.transcribe(audio_path)
return transcription['text']
# CrewAI Setup
def create_crew_agents(transcript_text):
research_agent = Agent(name="Research Agent", goal="Extract video transcript.")
blog_writer_agent = Agent(name="Blog Writer", goal="Generate blog content.")
editor_agent = Agent(name="Editor", goal="Refine blog for clarity.")
research_task = Task(description="Fetch transcript.", agent=research_agent)
blog_task = Task(description="Write blog using transcript.", agent=blog_writer_agent, context=transcript_text)
editor_task = Task(description="Edit the blog.", agent=editor_agent)
crew = Crew(agents=[research_agent, blog_writer_agent, editor_agent], tasks=[research_task, blog_task, editor_task])
return crew
# User Input for Video URL
video_url = st.text_input("Enter YouTube Video URL:")
if st.button("Generate Blog"):
if video_url:
try:
st.info("Fetching transcript...")
transcript_text = get_video_transcript(video_url) # Fetch transcript using CrewAI
st.text_area("Transcript Extracted", transcript_text, height=200)
# Generate Blog with CrewAI
crew = create_crew_agents(transcript_text)
results = crew.kickoff()
st.subheader("Generated Blog")
st.write(results)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please enter a valid YouTube URL.")
|