File size: 3,357 Bytes
469732e
e929452
469732e
e929452
469732e
 
a68d089
e929452
469732e
 
e929452
 
 
 
 
469732e
9ec95a2
469732e
 
e929452
95eb3ba
 
 
469732e
e929452
469732e
 
 
 
95eb3ba
469732e
 
 
e929452
 
 
469732e
 
 
 
 
 
 
 
 
 
 
 
e929452
 
 
469732e
 
e929452
469732e
e929452
 
 
 
 
 
 
469732e
 
 
e929452
 
 
 
 
 
 
 
469732e
 
e929452
469732e
e929452
 
 
 
 
 
 
469732e
 
e929452
469732e
 
e929452
469732e
 
 
 
 
 
 
e929452
 
 
 
 
 
 
469732e
 
e929452
469732e
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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 environment variables
load_dotenv()

# Apply nest_asyncio to allow nested event loops
nest_asyncio.apply()

# Initialize Google Gemini AI
llm = ChatGoogleGenerativeAI(
    api_key=os.getenv('GOOGLE_API_KEY'),
    model="models/gemini-pro"  # Replace with the correct model name
)

# Initialize the YoutubeChannelSearchTool without OpenAI dependency
# (Assuming it can be configured to not use OpenAI, or you might need to create a custom search tool)
yt_tool = YoutubeChannelSearchTool(youtube_channel_handle='@krishnaik06', use_openai=False)

# Define Agents
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
)

# Define Tasks
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'
)

# Define Crew
crew = Crew(
    agents=[blog_researcher, blog_writer],
    tasks=[research_task, write_task],
    verbose=2,
    memory=True,
    cache=True,
    max_rpm=100,
    share_crew=True
)

# Streamlit App
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()