poemsforaphrodite commited on
Commit
aea515f
·
verified ·
1 Parent(s): 39fa40f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -68
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 Marketing Analysis", layout="wide")
13
 
14
  # Streamlit UI
15
- st.title("SEO Marketing Analysis")
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
- # Define agents
29
- seo_researcher = Agent(
30
- role='SEO Research Analyst',
31
- goal='Uncover the latest SEO trends and strategies',
32
- backstory="""You are a seasoned SEO analyst with years of experience.
33
- Your expertise lies in identifying emerging trends and effective strategies in search engine optimization.""",
34
- verbose=True,
35
- allow_delegation=False,
36
- tools=[search_tool],
37
- llm=gpt4_model
38
- )
 
 
 
 
 
 
 
 
 
 
39
 
40
- content_strategist = Agent(
41
- role='Content Strategist',
42
- goal='Develop effective SEO content strategies',
43
- backstory="""You are a skilled content strategist known for your ability to create
44
- SEO-friendly content that ranks well and engages readers.""",
45
- verbose=True,
46
- allow_delegation=False,
47
- tools=[search_tool],
48
- llm=gpt4_model
49
- )
 
50
 
51
- # Create tasks
52
- research_task = Task(
53
- description="""Conduct comprehensive research on the current SEO trends and strategies.
54
- Identify the top 5 most effective SEO techniques for 2024.
55
- Provide a brief overview of each technique and why it's considered effective.""",
56
- expected_output="A detailed report listing 5 top SEO techniques with explanations of their effectiveness",
57
- agent=seo_researcher
58
- )
59
 
60
- strategy_task = Task(
61
- description="""Using the research provided, develop a comprehensive SEO content strategy.
62
- The strategy should include content types, keyword strategies, and content distribution methods.
63
- Provide practical examples and implementation tips.""",
64
- expected_output="A well-structured SEO content strategy report of at least 4 paragraphs",
65
- agent=content_strategist
66
- )
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- # Instantiate crew
69
- crew = Crew(
70
- agents=[seo_researcher, content_strategist],
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
- with st.spinner("Analyzing SEO trends and strategies..."):
79
- result = crew.kickoff()
80
-
81
- st.success("Analysis complete!")
82
-
83
- # Display the result
84
- st.markdown("## SEO Analysis Result")
85
- st.markdown(str(result))
86
-
87
- # Add a download button for the full report
88
- st.download_button(
89
- label="Download Full Report",
90
- data=str(result),
91
- file_name="seo_analysis_report.txt",
92
- mime="text/plain"
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 running the Streamlit app
98
- st.sidebar.header("How to Run")
99
  st.sidebar.info(
100
- "1. Ensure your OpenAI and Serper API Keys are in the .env file.\n"
101
- "2. Click the 'Start SEO Analysis' button to begin the analysis.\n"
102
- "3. Wait for the analysis to complete (this may take a few minutes).\n"
103
- "4. View the results in the main panel.\n"
104
- "5. Download the full report if desired."
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
  )