eaglelandsonce
commited on
Commit
•
997b388
1
Parent(s):
50c03f6
Update app.py
Browse files
app.py
CHANGED
@@ -10,39 +10,21 @@ from crewai.tools.browser_tools import BrowserTools
|
|
10 |
from crewai.tools.sec_tools import SECTools
|
11 |
|
12 |
# Google Langchain
|
13 |
-
#from langchain_google_genai import ChatGoogleGenerativeAI
|
14 |
-
|
15 |
from langchain_google_genai import GoogleGenerativeAI
|
16 |
|
|
|
17 |
from crewai import Agent, Task, Crew, Process
|
18 |
|
19 |
# Retrieve API Key from Environment Variable
|
20 |
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')
|
21 |
|
22 |
-
# os.environ["GOOGLE_API_KEY"] =
|
23 |
-
|
24 |
# Ensure the API key is available
|
25 |
if not GOOGLE_AI_STUDIO:
|
26 |
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
|
27 |
|
28 |
-
|
29 |
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)
|
30 |
|
31 |
-
|
32 |
-
# os.environ["OPENAI_API_KEY"] = "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"
|
33 |
-
|
34 |
-
# Crew Bot: https://chat.openai.com/g/g-qqTuUWsBY-crewai-assistant
|
35 |
-
|
36 |
-
|
37 |
-
'''
|
38 |
-
tools=[
|
39 |
-
GeminiSearchTools.gemini_search,
|
40 |
-
BrowserTools.scrape_and_summarize_website
|
41 |
-
|
42 |
-
]
|
43 |
-
'''
|
44 |
-
|
45 |
-
#llm = ChatGoogleGenerativeAI(model=model),
|
46 |
# Base Example with Gemini Search
|
47 |
|
48 |
def crewai_process(research_topic):
|
@@ -115,193 +97,3 @@ iface = gr.Interface(
|
|
115 |
# Launch the interface
|
116 |
iface.launch()
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
# Stock Evaluation
|
121 |
-
|
122 |
-
|
123 |
-
'''
|
124 |
-
from stock_analysis_agents import StockAnalysisAgents
|
125 |
-
from stock_analysis_tasks import StockAnalysisTasks
|
126 |
-
|
127 |
-
#from dotenv import load_dotenv
|
128 |
-
|
129 |
-
#load_dotenv()
|
130 |
-
|
131 |
-
def run_financial_analysis(company_name):
|
132 |
-
# Assuming StockAnalysisAgents and StockAnalysisTasks are defined elsewhere
|
133 |
-
agents = StockAnalysisAgents()
|
134 |
-
tasks = StockAnalysisTasks()
|
135 |
-
|
136 |
-
research_analyst_agent = agents.research_analyst()
|
137 |
-
financial_analyst_agent = agents.financial_analyst()
|
138 |
-
investment_advisor_agent = agents.investment_advisor()
|
139 |
-
|
140 |
-
research_task = tasks.research(research_analyst_agent, company_name)
|
141 |
-
financial_task = tasks.financial_analysis(financial_analyst_agent)
|
142 |
-
filings_task = tasks.filings_analysis(financial_analyst_agent)
|
143 |
-
recommend_task = tasks.recommend(investment_advisor_agent)
|
144 |
-
|
145 |
-
crew = Crew(
|
146 |
-
agents=[
|
147 |
-
research_analyst_agent,
|
148 |
-
financial_analyst_agent,
|
149 |
-
investment_advisor_agent
|
150 |
-
],
|
151 |
-
tasks=[
|
152 |
-
research_task,
|
153 |
-
financial_task,
|
154 |
-
filings_task,
|
155 |
-
recommend_task
|
156 |
-
],
|
157 |
-
verbose=True
|
158 |
-
)
|
159 |
-
|
160 |
-
result = crew.kickoff()
|
161 |
-
return result
|
162 |
-
|
163 |
-
iface = gr.Interface(
|
164 |
-
fn=run_financial_analysis,
|
165 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter Company Name Here"),
|
166 |
-
outputs="text",
|
167 |
-
title="CrewAI Financial Analysis",
|
168 |
-
description="Enter a company name to get financial analysis."
|
169 |
-
)
|
170 |
-
|
171 |
-
#if __name__ == "__main__":
|
172 |
-
iface.launch()
|
173 |
-
|
174 |
-
'''
|
175 |
-
|
176 |
-
|
177 |
-
# Therapy Group
|
178 |
-
|
179 |
-
'''
|
180 |
-
def run_therapy_session(group_size, topic):
|
181 |
-
participant_names = ['Alice', 'Bob', 'Charlie', 'Diana', 'Ethan', 'Fiona', 'George', 'Hannah', 'Ivan']
|
182 |
-
|
183 |
-
if group_size > len(participant_names) + 1: # +1 for the therapist
|
184 |
-
return "Group size exceeds the number of available participant names."
|
185 |
-
|
186 |
-
# Create the therapist agent
|
187 |
-
dr_smith = Agent(
|
188 |
-
role='Therapist',
|
189 |
-
goal='Facilitate a supportive group discussion',
|
190 |
-
backstory='An experienced therapist specializing in group dynamics.',
|
191 |
-
verbose=True,
|
192 |
-
allow_delegation=False
|
193 |
-
)
|
194 |
-
# Create participant agents
|
195 |
-
|
196 |
-
participants = [Agent(
|
197 |
-
role=f'Group Therapy Participant - {name}',
|
198 |
-
goal='Participate in group therapy',
|
199 |
-
backstory=f'{name} is interested in sharing and learning from the group.',
|
200 |
-
verbose=True,
|
201 |
-
allow_delegation=False)
|
202 |
-
for name in participant_names[:group_size - 1]]
|
203 |
-
participants.append(dr_smith)
|
204 |
-
|
205 |
-
# Define tasks for each participant
|
206 |
-
tasks = [Task(description=f'{participant.role.split(" - ")[-1]}, please share your thoughts on the topic: "{topic}".', agent=participant)
|
207 |
-
for participant in participants]
|
208 |
-
|
209 |
-
# Instantiate the crew with a sequential process
|
210 |
-
therapy_crew = Crew(
|
211 |
-
agents=participants,
|
212 |
-
tasks=tasks,
|
213 |
-
process=Process.sequential,
|
214 |
-
verbose=True
|
215 |
-
)
|
216 |
-
|
217 |
-
# Start the group therapy session
|
218 |
-
result = therapy_crew.kickoff()
|
219 |
-
|
220 |
-
# Simulating a conversation (placeholder, adjust based on CrewAI capabilities)
|
221 |
-
conversation = "\n".join([f"{participant.role.split(' - ')[-1]}: [Participant's thoughts on '{topic}']" for participant in participants])
|
222 |
-
|
223 |
-
return result
|
224 |
-
|
225 |
-
# Gradio interface
|
226 |
-
iface = gr.Interface(
|
227 |
-
fn=run_therapy_session,
|
228 |
-
inputs=[
|
229 |
-
gr.Slider(minimum=2, maximum=10, label="Group Size", value=4),
|
230 |
-
gr.Textbox(lines=2, placeholder="Enter a topic or question for discussion", label="Discussion Topic")
|
231 |
-
],
|
232 |
-
outputs="text"
|
233 |
-
)
|
234 |
-
|
235 |
-
# Launch the interface
|
236 |
-
iface.launch()
|
237 |
-
|
238 |
-
'''
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
# Choosing topics
|
244 |
-
|
245 |
-
'''
|
246 |
-
def run_crew(topic):
|
247 |
-
# Define your agents
|
248 |
-
researcher = Agent(
|
249 |
-
role='Senior Research Analyst',
|
250 |
-
goal='Uncover cutting-edge developments',
|
251 |
-
backstory="""You are a Senior Research Analyst at a leading tech think tank...""",
|
252 |
-
verbose=True,
|
253 |
-
allow_delegation=False
|
254 |
-
)
|
255 |
-
|
256 |
-
writer = Agent(
|
257 |
-
role='Tech Content Strategist',
|
258 |
-
goal='Craft compelling content',
|
259 |
-
backstory="""You are a renowned Tech Content Strategist...""",
|
260 |
-
verbose=True,
|
261 |
-
allow_delegation=False
|
262 |
-
)
|
263 |
-
|
264 |
-
# Assign tasks based on the selected topic
|
265 |
-
if topic == "write short story":
|
266 |
-
task_description = "Write a captivating short story about a journey through a futuristic city."
|
267 |
-
elif topic == "write an article":
|
268 |
-
task_description = "Compose an insightful article on the latest trends in technology."
|
269 |
-
elif topic == "analyze stock":
|
270 |
-
task_description = "Perform a detailed analysis of recent trends in the stock market."
|
271 |
-
elif topic == "create a vacation":
|
272 |
-
task_description = "Plan a perfect vacation itinerary for a family trip to Europe."
|
273 |
-
|
274 |
-
task1 = Task(
|
275 |
-
description=task_description,
|
276 |
-
agent=researcher
|
277 |
-
)
|
278 |
-
|
279 |
-
task2 = Task(
|
280 |
-
description=f"Use the findings from the researcher's task to develop a comprehensive report on '{topic}'.",
|
281 |
-
agent=writer
|
282 |
-
)
|
283 |
-
|
284 |
-
# Instantiate your crew with a sequential process
|
285 |
-
crew = Crew(
|
286 |
-
agents=[researcher, writer],
|
287 |
-
tasks=[task1, task2],
|
288 |
-
verbose=2,
|
289 |
-
process=Process.sequential
|
290 |
-
)
|
291 |
-
|
292 |
-
# Get your crew to work!
|
293 |
-
result = crew.kickoff()
|
294 |
-
return result
|
295 |
-
|
296 |
-
# Gradio Interface with Dropdown for Topic Selection
|
297 |
-
iface = gr.Interface(
|
298 |
-
fn=run_crew,
|
299 |
-
inputs=gr.Dropdown(choices=["write short story", "write an article", "analyze stock", "create a vacation"], label="Select Topic"),
|
300 |
-
outputs="text",
|
301 |
-
title="AI Research and Writing Crew",
|
302 |
-
description="Select a topic and click the button to run the crew of AI agents."
|
303 |
-
)
|
304 |
-
|
305 |
-
iface.launch()
|
306 |
-
|
307 |
-
'''
|
|
|
10 |
from crewai.tools.sec_tools import SECTools
|
11 |
|
12 |
# Google Langchain
|
|
|
|
|
13 |
from langchain_google_genai import GoogleGenerativeAI
|
14 |
|
15 |
+
#Crew imports
|
16 |
from crewai import Agent, Task, Crew, Process
|
17 |
|
18 |
# Retrieve API Key from Environment Variable
|
19 |
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')
|
20 |
|
|
|
|
|
21 |
# Ensure the API key is available
|
22 |
if not GOOGLE_AI_STUDIO:
|
23 |
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
|
24 |
|
25 |
+
# Set gemini_llm
|
26 |
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Base Example with Gemini Search
|
29 |
|
30 |
def crewai_process(research_topic):
|
|
|
97 |
# Launch the interface
|
98 |
iface.launch()
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|