File size: 8,800 Bytes
7200ed6 147252c ca6df07 147252c 57f10fe efe7912 6168534 57f10fe bfb2154 147252c cf348fc d2ca388 3a698b7 a600c86 3a698b7 a600c86 f995681 1c9438b 3a698b7 1c9438b 3a698b7 06e2e1e a600c86 3a698b7 bfb2154 3a698b7 1c9438b 3a698b7 1c9438b 3a698b7 a8ed030 3a698b7 a8ed030 3a698b7 147252c 3a698b7 c055605 1c9438b 3a698b7 f995681 1c9438b ca6df07 809349d ca6df07 a264ad8 c46f71f ca6df07 a264ad8 0d4abfa a264ad8 d03d6fd a264ad8 6847324 ca6df07 1c9438b 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
import os
import gradio as gr
from textwrap import dedent
# Tool import
from crewai.tools.gemini_tools import GeminiSearchTools
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool
from crewai.tools.browser_tools import BrowserTools
from crewai.tools.sec_tools import SECTools
from crewai import Agent, Task, Crew, Process
os.environ["OPENAI_API_KEY"] = "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"
# Crew Bot: https://chat.openai.com/g/g-qqTuUWsBY-crewai-assistant
'''
tools=[
GeminiSearchTools.gemini_search,
BrowserTools.scrape_and_summarize_website
]
'''
# Base Example with Gemini Search
def crewai_process(research_topic):
# Define your agents with roles and goals
researcher = Agent(
role='Senior Research Analyst',
goal=f'Uncover cutting-edge developments in {research_topic}',
backstory="""You are a Senior Research Analyst at a leading think tank.
Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting
actionable insights.""",
verbose=True,
allow_delegation=False,
tools=[
GeminiSearchTools.gemini_search
]
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a renowned Tech Content Strategist, known for your insightful
and engaging articles on technology and innovation. With a deep understanding of
the tech industry, you transform complex concepts into compelling narratives.""",
verbose=True,
allow_delegation=True
# Add tools and other optional parameters as needed
)
# Create tasks for your agents
task1 = Task(
description=f"""Conduct a comprehensive analysis of the latest advancements in {research_topic}.
Compile your findings in a detailed report. Your final answer MUST be a full analysis report""",
agent=researcher
)
task2 = Task(
description="""Using the insights from the researcher's report, develop an engaging blog
post that highlights the most significant advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Aim for a narrative that captures the essence of these breakthroughs and their
implications for the future. Your final answer MUST be the full blog post of at least 3 paragraphs.""",
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
# Create a Gradio interface
iface = gr.Interface(
fn=crewai_process,
inputs=gr.Textbox(lines=2, placeholder="Enter Research Topic Here..."),
outputs="text",
title="CrewAI Research and Writing Assistant",
description="Input a research topic to get a comprehensive analysis and a blog post draft."
)
# Launch the interface
iface.launch()
# Stock Evaluation
'''
from stock_analysis_agents import StockAnalysisAgents
from stock_analysis_tasks import StockAnalysisTasks
#from dotenv import load_dotenv
#load_dotenv()
def run_financial_analysis(company_name):
# Assuming StockAnalysisAgents and StockAnalysisTasks are defined elsewhere
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, company_name)
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
iface = gr.Interface(
fn=run_financial_analysis,
inputs=gr.Textbox(lines=2, placeholder="Enter Company Name Here"),
outputs="text",
title="CrewAI Financial Analysis",
description="Enter a company name to get financial analysis."
)
#if __name__ == "__main__":
iface.launch()
'''
# 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()
'''
|