|
import streamlit as st |
|
from crewai import Agent, Task, Crew |
|
from crewai_tools import YoutubeChannelSearchTool |
|
from langchain_google_genai import ChatGoogleGenerativeAI |
|
from dotenv import load_dotenv |
|
import os |
|
import nest_asyncio |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
nest_asyncio.apply() |
|
|
|
|
|
llm = ChatGoogleGenerativeAI( |
|
api_key=os.getenv('GOOGLE_API_KEY'), |
|
model="models/gemini-pro" |
|
) |
|
|
|
|
|
|
|
yt_tool = YoutubeChannelSearchTool(youtube_channel_handle='@krishnaik06', use_openai=False) |
|
|
|
|
|
blog_researcher = Agent( |
|
role='Blog Researcher from Youtube Videos', |
|
goal='Get the relevant video transcription for the topic {topic} from the provided YT channel', |
|
backstory=( |
|
"Expert in understanding videos in AI, Data Science, Machine Learning, and Gen AI and providing suggestions." |
|
), |
|
llm=llm, |
|
tools=[yt_tool], |
|
allow_delegation=True, |
|
verbose=True, |
|
memory=True |
|
) |
|
|
|
blog_writer = Agent( |
|
role='Blog Writer', |
|
goal='Narrate compelling tech stories about the video {topic} from YT video', |
|
backstory=( |
|
"With a flair for simplifying complex topics, you craft" |
|
"engaging narratives that captivate and educate, bringing new" |
|
"discoveries to light in an accessible manner." |
|
), |
|
llm=llm, |
|
tools=[yt_tool], |
|
allow_delegation=False, |
|
verbose=True, |
|
memory=True |
|
) |
|
|
|
|
|
research_task = Task( |
|
description=( |
|
"Identify the video {topic}. " |
|
"Get detailed information about the video from the channel video." |
|
), |
|
expected_output='A comprehensive 3 paragraphs long report based on the {topic} of video content.', |
|
agent=blog_researcher, |
|
tools=[yt_tool] |
|
) |
|
|
|
write_task = Task( |
|
description=( |
|
"Get the info from the YouTube channel on the topic {topic}." |
|
), |
|
expected_output='Summarize the info from the YouTube channel video on the topic {topic} and create the content for the blog', |
|
agent=blog_writer, |
|
tools=[yt_tool], |
|
async_execution=False, |
|
output_file='new-blog-post.md' |
|
) |
|
|
|
|
|
crew = Crew( |
|
agents=[blog_researcher, blog_writer], |
|
tasks=[research_task, write_task], |
|
verbose=2, |
|
memory=True, |
|
cache=True, |
|
max_rpm=100, |
|
share_crew=True |
|
) |
|
|
|
|
|
def main(): |
|
st.set_page_config(page_title="AI Blog Generator", page_icon="π") |
|
|
|
st.title("AI Blog Generator") |
|
st.write("Enter a topic to generate a blog post based on YouTube videos.") |
|
|
|
topic = st.text_input("Topic", "") |
|
if st.button("Generate Blog Post"): |
|
if topic: |
|
with st.spinner("Generating blog post..."): |
|
try: |
|
result = crew.kickoff(inputs={'topic': topic}) |
|
with open('new-blog-post.md', 'r') as file: |
|
blog_content = file.read() |
|
st.markdown(blog_content) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
else: |
|
st.error("Please enter a topic to continue.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|