Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import gradio as gr
|
4 |
+
from crewai import Agent, Task, Crew
|
5 |
+
# Importing crewAI tools
|
6 |
+
from crewai_tools import (
|
7 |
+
DirectoryReadTool,
|
8 |
+
FileReadTool,
|
9 |
+
SerperDevTool,
|
10 |
+
WebsiteSearchTool
|
11 |
+
)
|
12 |
+
|
13 |
+
# Load environment variables
|
14 |
+
load_dotenv()
|
15 |
+
|
16 |
+
# Get API keys from environment variables
|
17 |
+
SERPER_API_KEY = os.getenv("SERPER_API_KEY")
|
18 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
19 |
+
|
20 |
+
# Instantiate tools
|
21 |
+
file_tool = FileReadTool(file_path='plan2.txt') # Adjusted to read plan.txt
|
22 |
+
search_tool = SerperDevTool()
|
23 |
+
web_rag_tool = WebsiteSearchTool()
|
24 |
+
|
25 |
+
# Create agents
|
26 |
+
analyst = Agent(
|
27 |
+
role='Climate Strategy Analyst',
|
28 |
+
goal='Analyze the climate strategy plan to identify key requirements and objectives.',
|
29 |
+
backstory='An expert in climate strategy with experience in sustainable solutions.',
|
30 |
+
tools=[file_tool],
|
31 |
+
verbose=True
|
32 |
+
)
|
33 |
+
|
34 |
+
researcher = Agent(
|
35 |
+
role='Climate Tech Researcher',
|
36 |
+
goal='Find climate tech companies that provide solutions aligning with the strategy plan.',
|
37 |
+
backstory='A researcher specialized in identifying and evaluating climate technology solutions.',
|
38 |
+
tools=[search_tool, web_rag_tool],
|
39 |
+
verbose=True
|
40 |
+
)
|
41 |
+
|
42 |
+
# Define tasks
|
43 |
+
analyze_strategy = Task(
|
44 |
+
description='Analyze the climate strategy plan from plan.txt and extract key requirements.',
|
45 |
+
expected_output='A detailed list of key requirements and objectives from the climate strategy plan.',
|
46 |
+
agent=analyst
|
47 |
+
)
|
48 |
+
|
49 |
+
search_companies = Task(
|
50 |
+
description='Search for climate tech companies that offer solutions meeting the extracted strategy requirements.',
|
51 |
+
expected_output='A list of climate tech companies with brief descriptions of how their solutions align with the strategy needs.',
|
52 |
+
agent=researcher,
|
53 |
+
output_file='research_results/company_recommendations.md' # The results will be saved here
|
54 |
+
)
|
55 |
+
|
56 |
+
# Assemble a crew with planning enabled
|
57 |
+
crew = Crew(
|
58 |
+
agents=[analyst, researcher],
|
59 |
+
tasks=[analyze_strategy, search_companies],
|
60 |
+
verbose=True,
|
61 |
+
planning=True, # Enable planning feature
|
62 |
+
)
|
63 |
+
|
64 |
+
def run_crew():
|
65 |
+
# Create crew and execute tasks
|
66 |
+
crew = Crew(
|
67 |
+
agents=[analyst, researcher],
|
68 |
+
tasks=[analyze_strategy, search_companies],
|
69 |
+
verbose=True,
|
70 |
+
planning=True,
|
71 |
+
)
|
72 |
+
result = crew.kickoff()
|
73 |
+
|
74 |
+
# Read and return the content of the output file
|
75 |
+
with open('research_results/company_recommendations.md', 'r') as f:
|
76 |
+
return f.read()
|
77 |
+
|
78 |
+
# Create Gradio interface
|
79 |
+
iface = gr.Interface(
|
80 |
+
fn=run_crew,
|
81 |
+
inputs=[],
|
82 |
+
outputs=gr.Textbox(label="Results"),
|
83 |
+
title="Climate Tech Company Finder",
|
84 |
+
description="Click to analyze climate strategy and find relevant companies."
|
85 |
+
)
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
iface.launch()
|