DrishtiSharma commited on
Commit
32f7bd0
Β·
verified Β·
1 Parent(s): 7871a55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
3
  import pandas as np
 
4
  from datetime import datetime
5
  from langchain_core.messages import HumanMessage
6
  from tools import tools
@@ -84,11 +85,13 @@ def visualize_bmi_and_calories(bmi, calories):
84
  ax2.legend(loc="upper right")
85
 
86
  plt.tight_layout()
87
- plt_path = "bmi_calorie_chart.png"
88
- plt.savefig(plt_path)
 
 
89
  plt.close()
90
 
91
- return plt_path
92
 
93
 
94
  def calculate_calories(age, weight, height, activity_level, gender):
@@ -160,10 +163,10 @@ with gr.Blocks() as demo:
160
  response = run_graph(f"{message}\n\n{personalized_metrics}", history, user_details)
161
  history.append((f"{user_details['name']}", message))
162
  history.append(("FIT.AI", response))
163
- return history, ""
164
 
165
- submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, text_input])
166
- clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, text_input])
167
 
168
  # Actions
169
  calculate_button = gr.Button("Calculate")
@@ -180,4 +183,4 @@ with gr.Blocks() as demo:
180
  outputs=[bmi_output, calorie_output, bmi_chart]
181
  )
182
 
183
- demo.launch(share=True)
 
1
  import gradio as gr
2
  import matplotlib.pyplot as plt
3
  import pandas as np
4
+ import tempfile
5
  from datetime import datetime
6
  from langchain_core.messages import HumanMessage
7
  from tools import tools
 
85
  ax2.legend(loc="upper right")
86
 
87
  plt.tight_layout()
88
+
89
+ # Save to a temporary file
90
+ temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
91
+ plt.savefig(temp_file.name)
92
  plt.close()
93
 
94
+ return temp_file.name
95
 
96
 
97
  def calculate_calories(age, weight, height, activity_level, gender):
 
163
  response = run_graph(f"{message}\n\n{personalized_metrics}", history, user_details)
164
  history.append((f"{user_details['name']}", message))
165
  history.append(("FIT.AI", response))
166
+ return history, chart_path
167
 
168
+ submit_button.click(submit_message, inputs=[text_input, chatbot], outputs=[chatbot, bmi_chart])
169
+ clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, bmi_chart])
170
 
171
  # Actions
172
  calculate_button = gr.Button("Calculate")
 
183
  outputs=[bmi_output, calorie_output, bmi_chart]
184
  )
185
 
186
+ demo.launch(share=True)