File size: 2,205 Bytes
8dd523e
d2ca388
7200ed6
cf348fc
 
d2ca388
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
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
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()