Update app.py
Browse files
app.py
CHANGED
@@ -129,6 +129,48 @@ def calculate_calories(age, weight, height, activity_level, gender):
|
|
129 |
with gr.Blocks() as demo:
|
130 |
gr.Markdown("# FIT.AI - Your Fitness and Wellbeing Coach")
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
with gr.Tab("BMI and Calorie Calculator"):
|
133 |
with gr.Row():
|
134 |
with gr.Column():
|
@@ -164,27 +206,4 @@ with gr.Blocks() as demo:
|
|
164 |
outputs=[bmi_output, calorie_output, bmi_chart]
|
165 |
)
|
166 |
|
167 |
-
|
168 |
-
chatbot = gr.Chatbot(label="Chat with FIT.AI")
|
169 |
-
text_input = gr.Textbox(placeholder="Type your question here...", label="Your Question")
|
170 |
-
submit_button = gr.Button("Submit")
|
171 |
-
clear_button = gr.Button("Clear Chat")
|
172 |
-
|
173 |
-
def submit_message(message, history=[]):
|
174 |
-
user_details = {
|
175 |
-
"name": user_name.value,
|
176 |
-
"age": user_age.value,
|
177 |
-
"weight": user_weight.value,
|
178 |
-
"height": user_height.value,
|
179 |
-
"activity_level": activity_level.value,
|
180 |
-
"gender": user_gender.value
|
181 |
-
}
|
182 |
-
response = run_graph(message, history, user_details)
|
183 |
-
history.append(("User", message))
|
184 |
-
history.append(("FIT.AI", response))
|
185 |
-
return history, ""
|
186 |
-
|
187 |
-
submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, text_input])
|
188 |
-
clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, text_input])
|
189 |
-
|
190 |
-
demo.launch(share=True)
|
|
|
129 |
with gr.Blocks() as demo:
|
130 |
gr.Markdown("# FIT.AI - Your Fitness and Wellbeing Coach")
|
131 |
|
132 |
+
with gr.Tab("Chat with FIT.AI"):
|
133 |
+
with gr.Row():
|
134 |
+
with gr.Column():
|
135 |
+
user_name = gr.Textbox(placeholder="Enter your name", label="Name")
|
136 |
+
user_age = gr.Number(label="Age (years)", value=25, precision=0)
|
137 |
+
user_gender = gr.Dropdown(choices=["Male", "Female"], label="Gender", value="Male")
|
138 |
+
user_weight = gr.Number(label="Weight (kg)", value=70, precision=1)
|
139 |
+
user_height = gr.Number(label="Height (cm)", value=170, precision=1)
|
140 |
+
activity_level = gr.Dropdown(
|
141 |
+
choices=["Sedentary", "Lightly active", "Moderately active", "Very active", "Extra active"],
|
142 |
+
label="Activity Level",
|
143 |
+
value="Moderately active"
|
144 |
+
)
|
145 |
+
|
146 |
+
chatbot = gr.Chatbot(label="Chat with FIT.AI")
|
147 |
+
text_input = gr.Textbox(placeholder="Type your question here...", label="Your Question")
|
148 |
+
submit_button = gr.Button("Submit")
|
149 |
+
clear_button = gr.Button("Clear Chat")
|
150 |
+
|
151 |
+
def submit_message(message, history=[]):
|
152 |
+
user_details = {
|
153 |
+
"name": user_name.value,
|
154 |
+
"age": user_age.value,
|
155 |
+
"weight": user_weight.value,
|
156 |
+
"height": user_height.value,
|
157 |
+
"activity_level": activity_level.value,
|
158 |
+
"gender": user_gender.value
|
159 |
+
}
|
160 |
+
bmi, status = calculate_bmi(user_details["height"], user_details["weight"], user_details["gender"])
|
161 |
+
if bmi:
|
162 |
+
bmi_path = visualize_bmi(bmi)
|
163 |
+
calories = calculate_calories(user_details["age"], user_details["weight"], user_details["height"], user_details["activity_level"], user_details["gender"])
|
164 |
+
response = run_graph(message, history, user_details)
|
165 |
+
history.append(("User", message))
|
166 |
+
history.append(("FIT.AI", response + f"\nYour BMI is {bmi:.2f}, considered {status}.\nDaily calorie needs: {calories} kcal."))
|
167 |
+
return history, "", bmi_path
|
168 |
+
else:
|
169 |
+
return history, "Error in calculation.", ""
|
170 |
+
|
171 |
+
submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, text_input, chatbot])
|
172 |
+
clear_button.click(lambda: ([], "", ""), inputs=None, outputs=[chatbot, text_input, chatbot])
|
173 |
+
|
174 |
with gr.Tab("BMI and Calorie Calculator"):
|
175 |
with gr.Row():
|
176 |
with gr.Column():
|
|
|
206 |
outputs=[bmi_output, calorie_output, bmi_chart]
|
207 |
)
|
208 |
|
209 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|