File size: 7,583 Bytes
7200ed6 147252c ca6df07 fd234e5 57f10fe efe7912 6168534 57f10fe 9dceda0 c89663d 37bd10d bfb2154 1c477d1 a293459 1c477d1 997b388 bb41c4b 07cda62 fd234e5 71b294c fd234e5 997b388 50c03f6 f995681 1c9438b 54c9445 1f618f5 54c9445 3a698b7 0423b9f 9231d7e da8e865 0423b9f 9231d7e c140c84 0423b9f 9231d7e da8e865 0423b9f 8e74874 0423b9f 9231d7e da8e865 0423b9f 3a698b7 06e2e1e a562d9c 06e2e1e cecfa91 e7b63ad 06e2e1e a600c86 0423b9f 9231d7e da8e865 0423b9f cecfa91 0423b9f 3a698b7 0423b9f f72b262 da8e865 0423b9f 3a698b7 0423b9f 506056f fa6deb8 0423b9f 506056f 0423b9f 3a698b7 0423b9f 3a698b7 f596c77 0423b9f 3a698b7 f596c77 0423b9f f596c77 0423b9f f596c77 0423b9f dd37441 f596c77 95a3a25 0423b9f 3a698b7 4e0e2df f72b262 da8e865 4e0e2df f72b262 da8e865 4e0e2df f72b262 da8e865 4e0e2df f72b262 da8e865 f72b262 da8e865 3a698b7 d167f12 0423b9f f72b262 3a698b7 a8ed030 3a698b7 a8ed030 54c9445 3a698b7 ef368b1 54c9445 4c4c646 ef368b1 db2445c 1f618f5 db2445c 37389a4 4c4c646 db2445c ef368b1 147252c 3a698b7 777a1db c055605 |
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 |
import os
import gradio as gr
from textwrap import dedent
import google.generativeai as genai
# 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.tools.mixtral_tools import MixtralSearchTools
from crewai.tools.zephyr_tools import ZephyrSearchTools
# Google Langchain
from langchain_google_genai import GoogleGenerativeAI
#Crew imports
from crewai import Agent, Task, Crew, Process
# Retrieve API Key from Environment Variable
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')
# Ensure the API key is available
if not GOOGLE_AI_STUDIO:
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
# Set gemini_llm
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)
# Base Example with Gemini Search
TITLE1 = """<h1 align="center">SmartMix - Your Safe Place</h1>"""
TITLE2 = """<h3 align="left">"This is an agent simulated group therapy session providing a safe, judgment-free environment, allowing for open exploration of sensitive topics. Please input the topic you would like to discuss. Active phrases produce realistic interactions."</h3>"""
TITLE3 = """<h3 align="center">"To see active group discussion click on logs during run."</h3>"""
def crewai_process(research_topic):
# Define your agents with roles and goals
Emily = Agent(
role='Emily Mental Patient Graphic Designer Anxiety',
goal='To learn how to manage her anxiety in social situations through group therapy.',
backstory="""Emily is a 28-year-old graphic designer. She has always struggled with social anxiety,
making it difficult for her to participate in group settings. She joined the therapy group to improve
her social skills and manage her anxiety.""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_crazy
]
)
David = Agent(
role='David Mental Patient Musician Bipolar',
goal='To gain insights into managing his bipolar disorder through group therapy.',
backstory="""David, a 35-year-old musician, has been living with bipolar disorder for over a decade.
His condition has impacted his career and personal life. He seeks to understand his emotions better
and find stability through the group sessions.""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_normal
]
)
Sarah = Agent(
role='Sarah Mental Patient Former Teacher Depression',
goal='To find strategies to cope with her depression through group therapy.',
backstory="""Sarah, 42, is a former teacher who has been battling depression for several years.
The illness has led her to leave her job. She hopes to find new coping mechanisms and rediscover
her passion for teaching.""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_crazy
]
)
Michael = Agent(
role='Michael Mental Patient Ex-Soldier',
goal='To overcome his PTSD and return to a normal lifeand through group therapy.',
backstory="""Michael is a 30-year-old ex-soldier. He developed PTSD following his service.
Struggling with flashbacks and anxiety, he joined the group to seek support and ways to
return to civilian life smoothly.""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_normal
]
)
Lisa = Agent(
role='Lisa',
goal='To facilitate the group progress and assist each member in their personal goals through group therapy.',
backstory=""" Dr. Thompson is a seasoned psychologist specializing in group therapy.
With over 15 years of experience, she is skilled at creating a safe space for her patients
to explore and address their mental health challenges.""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
GeminiSearchTools.gemini_search
]
)
# Create tasks for your agents
task1 = Task(
description=f"""Introduction yourself and describe your current mood and any significant events from the week affecting their mental state.
""",
agent=Emily
)
task2 = Task(
description=f"""Introduction yourself and describe your current mood and any significant events from the week affecting their mental state.
""",
agent=David
)
task3 = Task(
description=f""" Introduction yourself and describe your current mood and any significant events from the week affecting their mental state.
""",
agent=Sarah
)
task4 = Task(
description=f""" Introduction yourself and describe your current mood and any significant events from the week affecting their mental state.
""",
agent=Michael
)
task5 = Task(
description=f""" Introduction yourselfand describe and welcome everyone to the group and express hope and support.
""",
agent=Lisa
)
task6 = Task(
description=f"""Discuss the topic of {research_topic}
Members share personal experiences and strategies. Use Mixtral
""",
agent=Emily
)
task7 = Task(
description=f"""Discuss the topic of {research_topic}
Members share personal experiences and strategies. Use Mixtral
""",
agent=David
)
task8 = Task(
description=f""" Discuss the topic of {research_topic}
Members share personal experiences and strategies. Use Mixtral
""",
agent=Sarah
)
task9 = Task(
description=f""" Discuss the topic of {research_topic}
Members share personal experiences and strategies. Use Mixtral
""",
agent=Michael
)
task10 = Task(
description=f""" Discuss the topic of {research_topic}
Members share personal experiences and strategies. Use Mixtral
""",
agent=Lisa
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[Emily, David, Sarah, Michael, Lisa ],
tasks=[task1, task2, task3, task4, task5, task6, task7, task8, task9, task10],
verbose=2,
process=Process.sequential
)
# Get your crew to work!
result = crew.kickoff()
return result
# Create a Gradio interface
with gr.Blocks() as iface:
gr.HTML(TITLE1)
gr.HTML(TITLE2)
gr.HTML(TITLE3)
with gr.Row():
with gr.Column(scale=1):
gr.Image(value="crewai/resources/smartmix.jpg")
with gr.Column(scale=5):
run_button_crewai = gr.Button(value="Run", variant="primary", scale=1)
run_button_crewai.click(
fn=crewai_process,
inputs=gr.Textbox(lines=2,label="Topic Input", placeholder="Enter Discussion Topic..."),
outputs=gr.Textbox(label="Group Synopsis"),
)
# Launch the interface
iface.launch(debug=True)
|