Spaces:
Sleeping
Sleeping
File size: 5,964 Bytes
7200ed6 147252c ca6df07 147252c cf348fc d2ca388 147252c c055605 ca6df07 c055605 147252c e11008c a8d0107 e11008c 147252c 7403211 e11008c 7403211 e11008c 7403211 c3d6c02 e11008c 7403211 147252c 3517f30 147252c a8d0107 147252c 7403211 166df92 147252c 288fd07 147252c 7a8be61 147252c c055605 147252c 92cc30f d2ca388 92cc30f d2ca388 8dd523e d2ca388 92cc30f d2ca388 8dd523e 92cc30f d2ca388 92cc30f d2ca388 8dd523e d2ca388 92cc30f d2ca388 8dd523e d2ca388 8dd523e d2ca388 92cc30f d2ca388 92cc30f 26c7910 d2ca388 92cc30f 71a99b7 d2ca388 147252c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
import os
import gradio as gr
from textwrap import dedent
from dotenv import load_dotenv
from crewai import Agent, Task, Crew, Process
os.environ["OPENAI_API_KEY"] = "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"
from crewai import Agent, Task, Crew, Process
# Crew Bot: https://chat.openai.com/g/g-qqTuUWsBY-crewai-assistant
from stock_analysis_agents import StockAnalysisAgents
from stock_analysis_tasks import StockAnalysisTasks
load_dotenv()
class FinancialCrew:
def __init__(self, company):
self.company = company
def run(self):
agents = StockAnalysisAgents()
tasks = StockAnalysisTasks()
research_analyst_agent = agents.research_analyst()
financial_analyst_agent = agents.financial_analyst()
investment_advisor_agent = agents.investment_advisor()
research_task = tasks.research(research_analyst_agent, self.company)
financial_task = tasks.financial_analysis(financial_analyst_agent)
filings_task = tasks.filings_analysis(financial_analyst_agent)
recommend_task = tasks.recommend(investment_advisor_agent)
crew = Crew(
agents=[
research_analyst_agent,
financial_analyst_agent,
investment_advisor_agent
],
tasks=[
research_task,
financial_task,
filings_task,
recommend_task
],
verbose=True
)
result = crew.kickoff()
return result
if __name__ == "__main__":
print("## Welcome to Financial Analysis Crew")
print('-------------------------------')
company = input(
dedent("""
What is the company you want to analyze?
"""))
financial_crew = FinancialCrew(company)
result = financial_crew.run()
print("\n\n########################")
print("## Here is the Report")
print("########################\n")
print(result)
# Therapy Group
'''
def run_therapy_session(group_size, topic):
participant_names = ['Alice', 'Bob', 'Charlie', 'Diana', 'Ethan', 'Fiona', 'George', 'Hannah', 'Ivan']
if group_size > len(participant_names) + 1: # +1 for the therapist
return "Group size exceeds the number of available participant names."
# Create the therapist agent
dr_smith = Agent(
role='Therapist',
goal='Facilitate a supportive group discussion',
backstory='An experienced therapist specializing in group dynamics.',
verbose=True,
allow_delegation=False
)
# Create participant agents
participants = [Agent(
role=f'Group Therapy Participant - {name}',
goal='Participate in group therapy',
backstory=f'{name} is interested in sharing and learning from the group.',
verbose=True,
allow_delegation=False)
for name in participant_names[:group_size - 1]]
participants.append(dr_smith)
# Define tasks for each participant
tasks = [Task(description=f'{participant.role.split(" - ")[-1]}, please share your thoughts on the topic: "{topic}".', agent=participant)
for participant in participants]
# Instantiate the crew with a sequential process
therapy_crew = Crew(
agents=participants,
tasks=tasks,
process=Process.sequential,
verbose=True
)
# Start the group therapy session
result = therapy_crew.kickoff()
# Simulating a conversation (placeholder, adjust based on CrewAI capabilities)
conversation = "\n".join([f"{participant.role.split(' - ')[-1]}: [Participant's thoughts on '{topic}']" for participant in participants])
return result
# Gradio interface
iface = gr.Interface(
fn=run_therapy_session,
inputs=[
gr.Slider(minimum=2, maximum=10, label="Group Size", value=4),
gr.Textbox(lines=2, placeholder="Enter a topic or question for discussion", label="Discussion Topic")
],
outputs="text"
)
# Launch the interface
iface.launch()
'''
# Choosing topics
'''
def run_crew(topic):
# Define your agents
researcher = Agent(
role='Senior Research Analyst',
goal='Uncover cutting-edge developments',
backstory="""You are a Senior Research Analyst at a leading tech think tank...""",
verbose=True,
allow_delegation=False
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content',
backstory="""You are a renowned Tech Content Strategist...""",
verbose=True,
allow_delegation=False
)
# Assign tasks based on the selected topic
if topic == "write short story":
task_description = "Write a captivating short story about a journey through a futuristic city."
elif topic == "write an article":
task_description = "Compose an insightful article on the latest trends in technology."
elif topic == "analyze stock":
task_description = "Perform a detailed analysis of recent trends in the stock market."
elif topic == "create a vacation":
task_description = "Plan a perfect vacation itinerary for a family trip to Europe."
task1 = Task(
description=task_description,
agent=researcher
)
task2 = Task(
description=f"Use the findings from the researcher's task to develop a comprehensive report on '{topic}'.",
agent=writer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2,
process=Process.sequential
)
# Get your crew to work!
result = crew.kickoff()
return result
# Gradio Interface with Dropdown for Topic Selection
iface = gr.Interface(
fn=run_crew,
inputs=gr.Dropdown(choices=["write short story", "write an article", "analyze stock", "create a vacation"], label="Select Topic"),
outputs="text",
title="AI Research and Writing Crew",
description="Select a topic and click the button to run the crew of AI agents."
)
iface.launch()
'''
|