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 # 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 AI and data science in {research_topic}', backstory="""You are a Senior Research Analyst at a leading tech think tank. Your expertise lies in identifying emerging trends and technologies in AI and data science. You have a knack for dissecting complex data and presenting actionable insights.""", verbose=True, allow_delegation=False, tools=[ GeminiSearchTools.gemini_search, YahooFinanceNewsTool(), BrowserTools.scrape_and_summarize_website, SECTools.search_10q, SECTools.search_10k ] ) 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 AI in 2024. Identify key trends, breakthrough technologies, and potential industry impacts 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 AI 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() '''