Spaces:
Runtime error
Runtime error
File size: 4,427 Bytes
7200ed6 147252c cf348fc d2ca388 147252c 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 |
import os
import gradio as gr
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
# 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()
'''
|