Update app.py
Browse files
app.py
CHANGED
@@ -143,7 +143,7 @@ with gr.Blocks() as demo:
|
|
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")
|
@@ -162,14 +162,15 @@ with gr.Blocks() as demo:
|
|
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(
|
166 |
-
history.append(
|
167 |
-
return history, ""
|
168 |
else:
|
169 |
-
|
|
|
170 |
|
171 |
-
submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, text_input
|
172 |
-
clear_button.click(lambda: ([], ""
|
173 |
|
174 |
with gr.Tab("BMI and Calorie Calculator"):
|
175 |
with gr.Row():
|
@@ -206,4 +207,4 @@ with gr.Blocks() as demo:
|
|
206 |
outputs=[bmi_output, calorie_output, bmi_chart]
|
207 |
)
|
208 |
|
209 |
-
demo.launch(share=True)
|
|
|
143 |
value="Moderately active"
|
144 |
)
|
145 |
|
146 |
+
chatbot = gr.Chatbot(label="Chat with FIT.AI", type="messages")
|
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")
|
|
|
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({"role": "user", "content": message})
|
166 |
+
history.append({"role": "assistant", "content": response + f"\nYour BMI is {bmi:.2f}, considered {status}.\nDaily calorie needs: {calories} kcal.", "image": bmi_path})
|
167 |
+
return history, ""
|
168 |
else:
|
169 |
+
history.append({"role": "assistant", "content": "Error in calculation."})
|
170 |
+
return history, ""
|
171 |
|
172 |
+
submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, text_input])
|
173 |
+
clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, text_input])
|
174 |
|
175 |
with gr.Tab("BMI and Calorie Calculator"):
|
176 |
with gr.Row():
|
|
|
207 |
outputs=[bmi_output, calorie_output, bmi_chart]
|
208 |
)
|
209 |
|
210 |
+
demo.launch(share=True)
|