Prathamesh1420 commited on
Commit
067106a
1 Parent(s): f41e75a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -72
app.py CHANGED
@@ -1,13 +1,14 @@
1
  import streamlit as st
2
- from crewai import Crew, Agent, Process, Task
3
- from tools import tool
4
  from langchain_google_genai import ChatGoogleGenerativeAI
 
 
5
 
6
- # Define your API keys directly in the code
 
7
  GOOGLE_API_KEY = "AIzaSyDy02GtpV6-VcdeCZNLJT-c4kWuPxBRbrI"
8
- SERPER_API_KEY = "uxSCra7XOaiojmWo3MIQ2xzFWkX2306yJY7YIVMsT771qLCaOJejKKQB7nKbRXd7"
9
 
10
- # Initialize Google Generative AI model
11
  llm = ChatGoogleGenerativeAI(
12
  model="gemini-1.5-flash",
13
  verbose=True,
@@ -15,90 +16,112 @@ llm = ChatGoogleGenerativeAI(
15
  google_api_key=GOOGLE_API_KEY
16
  )
17
 
18
- # Initialize the tool for internet searching capabilities
19
- from crewai_tools import SerperDevTool
20
- tool = SerperDevTool(api_key=SERPER_API_KEY)
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Define agents
23
- news_researcher = Agent(
24
- role="Senior Researcher",
25
- goal='Uncover groundbreaking technologies in {topic}',
26
- verbose=True,
27
- memory=True,
28
- backstory=(
29
- "Driven by curiosity, you're at the forefront of"
30
- "innovation, eager to explore and share knowledge that could change"
31
- "the world."
32
- ),
33
- tools=[tool],
34
- llm=llm,
35
- allow_delegation=True
36
  )
37
 
38
- news_writer = Agent(
39
- role='Writer',
40
- goal='Narrate compelling tech stories about {topic}',
41
- verbose=True,
42
- memory=True,
43
- backstory=(
44
- "With a flair for simplifying complex topics, you craft"
45
- "engaging narratives that captivate and educate, bringing new"
46
- "discoveries to light in an accessible manner."
47
- ),
48
- tools=[tool],
49
- llm=llm,
50
- allow_delegation=False
51
  )
52
 
53
- # Define tasks
54
- research_task = Task(
55
  description=(
56
- "Identify the next big trend in {topic}."
57
- "Focus on identifying pros and cons and the overall narrative."
58
- "Your final report should clearly articulate the key points,"
59
- "its market opportunities, and potential risks."
 
 
 
60
  ),
61
- expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
62
- tools=[tool],
63
- agent=news_researcher,
 
64
  )
65
 
66
- write_task = Task(
67
  description=(
68
- "Compose an insightful article on {topic}."
69
- "Focus on the latest trends and how it's impacting the industry."
70
- "This article should be easy to understand, engaging, and positive."
 
 
 
 
 
 
 
71
  ),
72
- expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
73
- tools=[tool],
74
- agent=news_writer,
75
- async_execution=False,
76
- output_file='new-blog-post.md' # Example of output customization
 
 
 
 
 
 
 
 
 
77
  )
78
 
79
  # Define Crew
80
  crew = Crew(
81
- agents=[news_researcher, news_writer],
82
- tasks=[research_task, write_task],
83
- process=Process.sequential,
84
  )
85
 
86
- # Streamlit UI
87
- st.set_page_config(
88
- page_title="Tech Research and Writing",
89
- page_icon="🔬",
90
- layout="wide",
91
- menu_items={"About": "# Made by Prathamesh Khade"}
92
- )
93
 
94
- st.title("Tech Research and Writing")
 
95
 
96
- topic = st.text_input("Enter a topic to research and write about:")
 
 
 
 
 
 
97
 
98
- if st.button("Start Task"):
99
- if topic:
100
- result = crew.kickoff(inputs={'topic': topic})
101
- st.write("Task Results:")
102
- st.write(result)
103
- else:
104
- st.error("Please enter a topic.")
 
1
  import streamlit as st
2
+ from crewai import Agent, Task, Crew
 
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
+ from dotenv import load_dotenv
5
+ import os
6
 
7
+ # Load environment variables
8
+ load_dotenv()
9
  GOOGLE_API_KEY = "AIzaSyDy02GtpV6-VcdeCZNLJT-c4kWuPxBRbrI"
 
10
 
11
+ # Define LLM
12
  llm = ChatGoogleGenerativeAI(
13
  model="gemini-1.5-flash",
14
  verbose=True,
 
16
  google_api_key=GOOGLE_API_KEY
17
  )
18
 
19
+ # Define Agents
20
+ planner = Agent(
21
+ role="Content Planner",
22
+ goal="Plan engaging and factually accurate content on {topic}",
23
+ backstory="You're working on planning a blog article "
24
+ "about the topic: {topic}."
25
+ "You collect information that helps the "
26
+ "audience learn something "
27
+ "and make informed decisions. "
28
+ "Your work is the basis for "
29
+ "the Content Writer to write an article on this topic.",
30
+ allow_delegation=False,
31
+ verbose=True
32
+ )
33
 
34
+ writer = Agent(
35
+ role="Content Writer",
36
+ goal="Write a compelling and well-structured blog post on {topic}.",
37
+ backstory="You're a writer who uses the content plan to create a detailed blog post. "
38
+ "Ensure it aligns with SEO best practices and the brand's voice.",
39
+ allow_delegation=False,
40
+ verbose=True
 
 
 
 
 
 
 
41
  )
42
 
43
+ editor = Agent(
44
+ role="Editor",
45
+ goal="Edit a given blog post to align with the writing style of the organization.",
46
+ backstory="You are an editor who receives a blog post "
47
+ "from the Content Writer. "
48
+ "Your goal is to review the blog post "
49
+ "to ensure that it follows journalistic best practices,"
50
+ "provides balanced viewpoints "
51
+ "when providing opinions or assertions, "
52
+ "and also avoids major controversial topics "
53
+ "or opinions when possible.",
54
+ allow_delegation=False,
55
+ verbose=True
56
  )
57
 
58
+ # Define Tasks
59
+ plan = Task(
60
  description=(
61
+ "1. Prioritize the latest trends, key players, "
62
+ "and noteworthy news on {topic}.\n"
63
+ "2. Identify the target audience, considering "
64
+ "their interests and pain points.\n"
65
+ "3. Develop a detailed content outline including "
66
+ "an introduction, key points, and a call to action.\n"
67
+ "4. Include SEO keywords and relevant data or sources."
68
  ),
69
+ expected_output="A comprehensive content plan document "
70
+ "with an outline, audience analysis, "
71
+ "SEO keywords, and resources.",
72
+ agent=planner,
73
  )
74
 
75
+ write = Task(
76
  description=(
77
+ "1. Use the content plan to craft a compelling "
78
+ "blog post on {topic}.\n"
79
+ "2. Incorporate SEO keywords naturally.\n"
80
+ "3. Sections/Subtitles are properly named "
81
+ "in an engaging manner.\n"
82
+ "4. Ensure the post is structured with an "
83
+ "engaging introduction, insightful body, "
84
+ "and a summarizing conclusion.\n"
85
+ "5. Proofread for grammatical errors and "
86
+ "alignment with the brand's voice.\n"
87
  ),
88
+ expected_output="A well-written blog post "
89
+ "in markdown format, ready for publication, "
90
+ "each section should have 2 or 3 paragraphs.",
91
+ agent=writer,
92
+ )
93
+
94
+ edit = Task(
95
+ description=("Proofread the given blog post for "
96
+ "grammatical errors and "
97
+ "alignment with the brand's voice."),
98
+ expected_output="A well-written blog post in markdown format, "
99
+ "ready for publication, "
100
+ "each section should have 2 or 3 paragraphs.",
101
+ agent=editor
102
  )
103
 
104
  # Define Crew
105
  crew = Crew(
106
+ agents=[planner, writer, editor],
107
+ tasks=[plan, write, edit],
108
+ verbose=2
109
  )
110
 
111
+ # Streamlit App
112
+ def main():
113
+ st.title("Content Creation Assistant")
 
 
 
 
114
 
115
+ # Input for topic
116
+ topic = st.text_input("Enter the topic for the blog post:")
117
 
118
+ if st.button("Generate Content"):
119
+ if topic:
120
+ with st.spinner('Generating content...'):
121
+ result = crew.kickoff(inputs={"topic": topic})
122
+ st.markdown(result)
123
+ else:
124
+ st.error("Please enter a topic.")
125
 
126
+ if __name__ == "__main__":
127
+ main()