Prathamesh1420 commited on
Commit
469732e
Β·
verified Β·
1 Parent(s): db203fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -25
app.py CHANGED
@@ -1,25 +1,107 @@
1
- import streamlit as st
2
- from crew import run_task
3
- from dotenv import load_dotenv
4
- import os
5
-
6
- load_dotenv()
7
-
8
- def main():
9
- st.set_page_config(page_title="AI Blog Generator", page_icon="πŸ“")
10
-
11
- st.title("AI Blog Generator")
12
- st.write("Enter a topic to generate a blog post based on YouTube videos.")
13
-
14
- topic = st.text_input("Topic", "")
15
- if st.button("Generate Blog Post"):
16
- if topic:
17
- with st.spinner("Generating blog post..."):
18
- result = run_task(topic)
19
- st.success("Blog post generated!")
20
- st.markdown(result)
21
- else:
22
- st.error("Please enter a topic to continue.")
23
-
24
- if __name__ == "__main__":
25
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from crewai import Task, Agent, Crew, Process
3
+ from crewai_tools import YoutubeChannelSearchTool
4
+ from dotenv import load_dotenv
5
+ import os
6
+
7
+ # Load environment variables
8
+ load_dotenv()
9
+ llm = ChatGoogleGenerativeAI(
10
+ api_key=os.getenv('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'),
11
+ model="models/gemini-pro" # Replace with the correct model name
12
+ )
13
+
14
+ # Initialize the YoutubeChannelSearchTool with a specific Youtube channel handle to target your search
15
+ yt_tool = YoutubeChannelSearchTool(youtube_channel_handle='@krishnaik06')
16
+
17
+ # Define agents
18
+ ## Create a senior blog content researcher
19
+ blog_researcher = Agent(
20
+ role='Blog Researcher from Youtube Videos',
21
+ goal='Get the relevant video transcription for the topic {topic} from the provided YT channel',
22
+ verbose=True,
23
+ memory=True,
24
+ backstory=(
25
+ "Expert in understanding videos in AI, Data Science, Machine Learning, and Gen AI and providing suggestions."
26
+ ),
27
+ llm=llm,
28
+ tools=[yt_tool],
29
+ allow_delegation=True
30
+ )
31
+
32
+ ## Create a senior blog writer agent with YT tool
33
+ blog_writer = Agent(
34
+ role='Blog Writer',
35
+ goal='Narrate compelling tech stories about the video {topic} from YT video',
36
+ verbose=True,
37
+ memory=True,
38
+ backstory=(
39
+ "With a flair for simplifying complex topics, you craft"
40
+ "engaging narratives that captivate and educate, bringing new"
41
+ "discoveries to light in an accessible manner."
42
+ ),
43
+ llm=llm,
44
+ tools=[yt_tool],
45
+ allow_delegation=False
46
+ )
47
+
48
+ # Define tasks
49
+ ## Research Task
50
+ research_task = Task(
51
+ description=(
52
+ "Identify the video {topic}."
53
+ "Get detailed information about the video from the channel video."
54
+ ),
55
+ expected_output='A comprehensive 3 paragraphs long report based on the {topic} of video content.',
56
+ tools=[yt_tool],
57
+ agent=blog_researcher,
58
+ )
59
+
60
+ # Writing task with language model configuration
61
+ write_task = Task(
62
+ description=(
63
+ "get the info from the youtube channel on the topic {topic}."
64
+ ),
65
+ expected_output='Summarize the info from the youtube channel video on the topic {topic} and create the content for the blog',
66
+ tools=[yt_tool],
67
+ agent=blog_writer,
68
+ async_execution=False,
69
+ output_file='new-blog-post.md' # Example of output customization
70
+ )
71
+
72
+ # Forming the tech-focused crew with some enhanced configurations
73
+ crew = Crew(
74
+ agents=[blog_researcher, blog_writer],
75
+ tasks=[research_task, write_task],
76
+ process=Process.sequential, # Optional: Sequential task execution is default
77
+ memory=True,
78
+ cache=True,
79
+ max_rpm=100,
80
+ share_crew=True
81
+ )
82
+
83
+ def run_task(topic):
84
+ # Start the task execution process with enhanced feedback
85
+ result = crew.kickoff(inputs={'topic': topic})
86
+ with open('new-blog-post.md', 'r') as file:
87
+ blog_content = file.read()
88
+ return blog_content
89
+
90
+ def main():
91
+ st.set_page_config(page_title="AI Blog Generator", page_icon="πŸ“")
92
+
93
+ st.title("AI Blog Generator")
94
+ st.write("Enter a topic to generate a blog post based on YouTube videos.")
95
+
96
+ topic = st.text_input("Topic", "")
97
+ if st.button("Generate Blog Post"):
98
+ if topic:
99
+ with st.spinner("Generating blog post..."):
100
+ result = run_task(topic)
101
+ st.success("Blog post generated!")
102
+ st.markdown(result)
103
+ else:
104
+ st.error("Please enter a topic to continue.")
105
+
106
+ if __name__ == "__main__":
107
+ main()