Spaces:
Runtime error
Runtime error
Prathamesh1420
commited on
Commit
•
067106a
1
Parent(s):
f41e75a
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
-
from crewai import
|
3 |
-
from tools import tool
|
4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
|
5 |
|
6 |
-
#
|
|
|
7 |
GOOGLE_API_KEY = "AIzaSyDy02GtpV6-VcdeCZNLJT-c4kWuPxBRbrI"
|
8 |
-
SERPER_API_KEY = "uxSCra7XOaiojmWo3MIQ2xzFWkX2306yJY7YIVMsT771qLCaOJejKKQB7nKbRXd7"
|
9 |
|
10 |
-
#
|
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 |
-
#
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
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 |
-
|
39 |
-
role=
|
40 |
-
goal=
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
)
|
52 |
|
53 |
-
# Define
|
54 |
-
|
55 |
description=(
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"
|
|
|
|
|
|
|
60 |
),
|
61 |
-
expected_output=
|
62 |
-
|
63 |
-
|
|
|
64 |
)
|
65 |
|
66 |
-
|
67 |
description=(
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
),
|
72 |
-
expected_output=
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
)
|
78 |
|
79 |
# Define Crew
|
80 |
crew = Crew(
|
81 |
-
agents=[
|
82 |
-
tasks=[
|
83 |
-
|
84 |
)
|
85 |
|
86 |
-
# Streamlit
|
87 |
-
|
88 |
-
|
89 |
-
page_icon="🔬",
|
90 |
-
layout="wide",
|
91 |
-
menu_items={"About": "# Made by Prathamesh Khade"}
|
92 |
-
)
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
if
|
99 |
-
|
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()
|
|
|
|
|
|
|
|
|
|