generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
222 lines (200 loc) · 6.85 KB
/
app.py
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
220
from crewai import Agent, Task, Crew, Process
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_community.tools import DuckDuckGoSearchRun
from langchain.agents import Tool
import gradio as gr
# Set gemini pro as llm
llm = ChatGoogleGenerativeAI(model="gemini-pro",
verbose=True,
temperature=0.5,
google_api_key="")
duckduckgo_search = DuckDuckGoSearchRun()
def create_crewai_setup(age, gender, disease):
# Define Agents
fitness_expert = Agent(
role="Fitness Expert",
goal=f"""Analyze the fitness requirements for a {age}-year-old {gender} with {disease} and
suggest exercise routines and fitness strategies""",
backstory=f"""Expert at understanding fitness needs, age-specific requirements,
and gender-specific considerations. Skilled in developing
customized exercise routines and fitness strategies.""",
verbose=True,
llm=llm,
allow_delegation=True,
tools=[duckduckgo_search],
)
nutritionist = Agent(
role="Nutritionist",
goal=f"""Assess nutritional requirements for a {age}-year-old {gender} with {disease} and
provide dietary recommendations""",
backstory=f"""Knowledgeable in nutrition for different age groups and genders,
especially for individuals of {age} years old. Provides tailored
dietary advice based on specific nutritional needs.""",
verbose=True,
llm=llm,
allow_delegation=True,
)
doctor = Agent(
role="Doctor",
goal=f"""Evaluate the overall health connsiderations for a {age}-year-old {gender} with {disease} and
provide recommendations for a healthy lifestyle. Pass it on to the disease_expert if you are not an expert of {disease}""",
backstory=f"""Medical professional experienced in assessing overall health and
well-being. Offers recommendations for a healthy llifestyle
considering age, gender, and disease factors.""",
verbose=True,
llm=llm,
allow_delegation=True,
)
# Check if the person has a disease
if disease.lower() == "yes":
disease_expert = Agent(
role="Disease Expert",
goal=f"""Provide recommendations for managing {disease}""",
backstory=f"""Specialized in dealing with individuals having {disease}.
Offers tailored advice for managing the specific health condition.
Do not prescribe medicines but only give advice.""",
verbose=True,
llm=llm,
allow_delegation=True,
)
disease_task = Task(
description=f"""Provide recommendations for managing {disease}""",
agent=disease_expert,
llm=llm,
expected_output="Recommendations for managing the specific disease"
)
health_crew = Crew(
agents=[fitness_expert, nutritionist, doctor, disease_expert],
tasks=[task1, task2, task3, disease_task],
verbose=2,
process=Process.sequential,
)
else:
# Define Tasks without Disease Expert
task1 = Task(
description=f"""Analyze the fitness requirements for a {age}-year-old {gender}.
Provide recommendations for exercise routines and fitness strategies.""",
agent=fitness_expert,
llm=llm,
expected_output="Exercise routines and fitness strategies"
)
task2 = Task(
description=f"""Assess nutritional requirements for a {age}-year-old {gender}.
Provide dietary recommendations based on specific nutritional needs.
Do not prescribe a medicine""",
agent=nutritionist,
llm=llm,
expected_output="Dietary recommendations"
)
task3 = Task(
description=f"""Evaluate overall health considerations for a {age}-year-old {gender}.
Provide recommendations for a healthy lifestyle.""",
agent=doctor,
llm=llm,
expected_output="Healthy lifestyle recommendations"
)
health_crew = Crew(
agents=[fitness_expert, nutritionist, doctor],
tasks=[task1, task2, task3],
verbose=2,
process=Process.sequential,
)
# Create and Run the Crew
crew_result = health_crew.kickoff()
# Write "No disease" if the user does not have a disease
if disease.lower() != "yes":
crew_result += f"\n disease: {disease}"
return crew_result
# Gradio interface
def run_crewai_app(age, gender, disease):
crew_result = create_crewai_setup(age, gender, disease)
return crew_result
# Custom CSS for styling
css = """
body {
background-color: #f5f5f5;
font-family: 'Roboto', sans-serif;
color: #333333;
}
.gradio-container {
background: #1b114a;
border-radius: 8px;
padding: 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
max-width: 800px;
margin: auto;
}
h1, h3 {
color: #ff6f00;
text-align: center;
}
.description {
color: #666666;
text-align: center;
margin-bottom: 20px;
}
#component-0 {
margin-bottom: 20px;
}
label {
font-weight: bold;
margin-bottom: 10px;
display: block;
}
input, select, textarea {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 20px;
border: 1px solid #dddddd;
border-radius: 4px;
font-size: 16px;
}
button {
background-color: #ff6f00;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #ff8c00;
}
#output {
margin-top: 20px;
padding: 20px;
border-radius: 8px;
background-color: #1b114a;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
font-size: 16px;
line-height: 1.5;
}
#output h2 {
font-size: 24px;
margin-bottom: 10px;
color: #ff6f00;
}
#output h3 {
font-size: 20px;
margin-bottom: 10px;
color: #ff8c00;
}
#output p {
margin-bottom: 10px;
}
"""
iface = gr.Interface(
fn=run_crewai_app,
inputs=[
gr.Number(label="Age"),
gr.Dropdown(label="Gender", choices=["Select your gender", "Male", "Female", "Other"]),
gr.Textbox(label="Disease", placeholder="Enter disease or 'no' if none"),
],
outputs=gr.HTML(label="Output", elem_id="output"),
title="CrewAI Health, Nutrition, and Fitness Analysis",
description="Enter your age, gender, and whether you have any disease to receive personalized fitness, nutrition, and health strategies.",
theme="default",
css=css
)
iface.launch(share=True)