crew-climate / app.py
poemsforaphrodite's picture
Create app.py
440d36a verified
raw
history blame
2.73 kB
import os
from dotenv import load_dotenv
import gradio as gr
from crewai import Agent, Task, Crew
# Importing crewAI tools
from crewai_tools import (
DirectoryReadTool,
FileReadTool,
SerperDevTool,
WebsiteSearchTool
)
# Load environment variables
load_dotenv()
# Get API keys from environment variables
SERPER_API_KEY = os.getenv("SERPER_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
# Instantiate tools
file_tool = FileReadTool(file_path='plan2.txt') # Adjusted to read plan.txt
search_tool = SerperDevTool()
web_rag_tool = WebsiteSearchTool()
# Create agents
analyst = Agent(
role='Climate Strategy Analyst',
goal='Analyze the climate strategy plan to identify key requirements and objectives.',
backstory='An expert in climate strategy with experience in sustainable solutions.',
tools=[file_tool],
verbose=True
)
researcher = Agent(
role='Climate Tech Researcher',
goal='Find climate tech companies that provide solutions aligning with the strategy plan.',
backstory='A researcher specialized in identifying and evaluating climate technology solutions.',
tools=[search_tool, web_rag_tool],
verbose=True
)
# Define tasks
analyze_strategy = Task(
description='Analyze the climate strategy plan from plan.txt and extract key requirements.',
expected_output='A detailed list of key requirements and objectives from the climate strategy plan.',
agent=analyst
)
search_companies = Task(
description='Search for climate tech companies that offer solutions meeting the extracted strategy requirements.',
expected_output='A list of climate tech companies with brief descriptions of how their solutions align with the strategy needs.',
agent=researcher,
output_file='research_results/company_recommendations.md' # The results will be saved here
)
# Assemble a crew with planning enabled
crew = Crew(
agents=[analyst, researcher],
tasks=[analyze_strategy, search_companies],
verbose=True,
planning=True, # Enable planning feature
)
def run_crew():
# Create crew and execute tasks
crew = Crew(
agents=[analyst, researcher],
tasks=[analyze_strategy, search_companies],
verbose=True,
planning=True,
)
result = crew.kickoff()
# Read and return the content of the output file
with open('research_results/company_recommendations.md', 'r') as f:
return f.read()
# Create Gradio interface
iface = gr.Interface(
fn=run_crew,
inputs=[],
outputs=gr.Textbox(label="Results"),
title="Climate Tech Company Finder",
description="Click to analyze climate strategy and find relevant companies."
)
if __name__ == "__main__":
iface.launch()