Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,10 @@ from crewai_tools import SerperDevTool
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
# Set up Streamlit page configuration
|
| 12 |
-
st.set_page_config(page_title="SEO
|
| 13 |
|
| 14 |
# Streamlit UI
|
| 15 |
-
st.title("SEO
|
| 16 |
|
| 17 |
# Get the API keys from environment variables
|
| 18 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
|
@@ -25,81 +25,108 @@ if openai_api_key and serper_api_key:
|
|
| 25 |
# Create a SerperDevTool instance
|
| 26 |
search_tool = SerperDevTool()
|
| 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 |
-
tasks=[research_task, strategy_task],
|
| 72 |
-
verbose=True,
|
| 73 |
-
process=Process.sequential
|
| 74 |
-
)
|
| 75 |
|
| 76 |
# Button to start the analysis
|
| 77 |
if st.button("Start SEO Analysis"):
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
else:
|
| 95 |
st.error("API keys not found in .env file. Please add OPENAI_API_KEY and SERPER_API_KEY and restart the app.")
|
| 96 |
|
| 97 |
-
# Instructions for
|
| 98 |
-
st.sidebar.header("How to
|
| 99 |
st.sidebar.info(
|
| 100 |
-
"1.
|
| 101 |
-
"2.
|
| 102 |
-
"3.
|
| 103 |
-
"4.
|
| 104 |
-
"5.
|
| 105 |
)
|
|
|
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
# Set up Streamlit page configuration
|
| 12 |
+
st.set_page_config(page_title="SEO Crew Builder", layout="wide")
|
| 13 |
|
| 14 |
# Streamlit UI
|
| 15 |
+
st.title("SEO Crew Builder")
|
| 16 |
|
| 17 |
# Get the API keys from environment variables
|
| 18 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 25 |
# Create a SerperDevTool instance
|
| 26 |
search_tool = SerperDevTool()
|
| 27 |
|
| 28 |
+
# Predefined SEO agent roles with default goals, backstories, and tasks
|
| 29 |
+
seo_roles = {
|
| 30 |
+
"SEO Strategist": {
|
| 31 |
+
"goal": "Develop comprehensive SEO strategies to improve website visibility and rankings",
|
| 32 |
+
"backstory": "An experienced SEO professional with a track record of boosting organic traffic for various industries.",
|
| 33 |
+
"task": "Conduct a comprehensive analysis of our website's current SEO performance and develop a strategy to improve our rankings for key target keywords.",
|
| 34 |
+
"expected_output": "A detailed SEO strategy report with actionable recommendations."
|
| 35 |
+
},
|
| 36 |
+
"Content Optimizer": {
|
| 37 |
+
"goal": "Analyze and optimize website content to align with SEO best practices and target keywords",
|
| 38 |
+
"backstory": "A skilled writer and editor with deep knowledge of SEO content creation and optimization techniques.",
|
| 39 |
+
"task": "Review our top 5 underperforming blog posts and provide specific recommendations for optimizing them to improve search engine rankings.",
|
| 40 |
+
"expected_output": "A report with optimization recommendations for 5 blog posts."
|
| 41 |
+
},
|
| 42 |
+
"Technical SEO Specialist": {
|
| 43 |
+
"goal": "Identify and resolve technical SEO issues to improve website performance and crawlability",
|
| 44 |
+
"backstory": "A tech-savvy SEO expert with a strong background in web development and search engine algorithms.",
|
| 45 |
+
"task": "Perform a technical SEO audit of our website, identifying any issues that may be hindering our search performance, and provide a prioritized list of fixes.",
|
| 46 |
+
"expected_output": "A comprehensive technical SEO audit report with a prioritized list of fixes."
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
|
| 50 |
+
# Function to create an agent
|
| 51 |
+
def create_agent(role, goal, backstory):
|
| 52 |
+
return Agent(
|
| 53 |
+
role=role,
|
| 54 |
+
goal=goal,
|
| 55 |
+
backstory=backstory,
|
| 56 |
+
verbose=True,
|
| 57 |
+
allow_delegation=False,
|
| 58 |
+
tools=[search_tool],
|
| 59 |
+
llm=gpt4_model
|
| 60 |
+
)
|
| 61 |
|
| 62 |
+
# Function to create a task
|
| 63 |
+
def create_task(description, expected_output, agent):
|
| 64 |
+
return Task(
|
| 65 |
+
description=description,
|
| 66 |
+
expected_output=expected_output,
|
| 67 |
+
agent=agent
|
| 68 |
+
)
|
|
|
|
| 69 |
|
| 70 |
+
# Sidebar for agent creation
|
| 71 |
+
st.sidebar.header("Create SEO Agents")
|
| 72 |
+
agents = []
|
| 73 |
+
tasks = []
|
| 74 |
+
for i, (default_role, details) in enumerate(seo_roles.items()):
|
| 75 |
+
with st.sidebar.expander(f"Agent {i+1}"):
|
| 76 |
+
role = st.text_input(f"Role for Agent {i+1}", value=default_role, key=f"role_{i}")
|
| 77 |
+
goal = st.text_input(f"Goal for Agent {i+1}", value=details['goal'], key=f"goal_{i}")
|
| 78 |
+
backstory = st.text_area(f"Backstory for Agent {i+1}", value=details['backstory'], key=f"backstory_{i}")
|
| 79 |
+
|
| 80 |
+
if role and goal and backstory:
|
| 81 |
+
agent = create_agent(role, goal, backstory)
|
| 82 |
+
agents.append(agent)
|
| 83 |
+
|
| 84 |
+
# Create task for this agent
|
| 85 |
+
task_description = st.text_area(f"Task for {role}", value=details['task'], key=f"task_{i}")
|
| 86 |
+
expected_output = st.text_input(f"Expected Output for {role}", value=details['expected_output'], key=f"output_{i}")
|
| 87 |
+
if task_description and expected_output:
|
| 88 |
+
tasks.append(create_task(task_description, expected_output, agent))
|
| 89 |
|
| 90 |
+
# Process selection
|
| 91 |
+
process = st.radio("Select Process", ["Sequential", "Hierarchical"])
|
| 92 |
+
process_enum = Process.sequential if process == "Sequential" else Process.hierarchical
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Button to start the analysis
|
| 95 |
if st.button("Start SEO Analysis"):
|
| 96 |
+
if agents and tasks:
|
| 97 |
+
with st.spinner("SEO Crew is working on the tasks..."):
|
| 98 |
+
crew = Crew(
|
| 99 |
+
agents=agents,
|
| 100 |
+
tasks=tasks,
|
| 101 |
+
verbose=True,
|
| 102 |
+
process=process_enum
|
| 103 |
+
)
|
| 104 |
+
result = crew.kickoff()
|
| 105 |
+
|
| 106 |
+
st.success("SEO Analysis complete!")
|
| 107 |
+
|
| 108 |
+
# Display the result
|
| 109 |
+
st.markdown("## SEO Analysis Result")
|
| 110 |
+
st.markdown(str(result))
|
| 111 |
+
|
| 112 |
+
# Add a download button for the full report
|
| 113 |
+
st.download_button(
|
| 114 |
+
label="Download Full SEO Report",
|
| 115 |
+
data=str(result),
|
| 116 |
+
file_name="seo_analysis_report.txt",
|
| 117 |
+
mime="text/plain"
|
| 118 |
+
)
|
| 119 |
+
else:
|
| 120 |
+
st.error("Please create at least one agent and one task before starting the analysis.")
|
| 121 |
else:
|
| 122 |
st.error("API keys not found in .env file. Please add OPENAI_API_KEY and SERPER_API_KEY and restart the app.")
|
| 123 |
|
| 124 |
+
# Instructions for using the app
|
| 125 |
+
st.sidebar.header("How to Use")
|
| 126 |
st.sidebar.info(
|
| 127 |
+
"1. Customize SEO agents in the sidebar by modifying their roles, goals, and backstories.\n"
|
| 128 |
+
"2. Modify the tasks for each agent if needed.\n"
|
| 129 |
+
"3. Select the process type (Sequential or Hierarchical).\n"
|
| 130 |
+
"4. Click 'Start SEO Analysis' to run the crew.\n"
|
| 131 |
+
"5. View the results and download the report if desired."
|
| 132 |
)
|