from crewai import Agent, Task, Crew, Process import gradio as gr import os os.environ["OPENAI_API_KEY"] = "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" 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()