rairo commited on
Commit
d537a56
·
verified ·
1 Parent(s): 546ba2c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -14
main.py CHANGED
@@ -32,17 +32,28 @@ app = Flask(__name__)
32
  cors = CORS(app)
33
 
34
  class FlaskResponse(ResponseParser):
35
- def __init__(self,context) -> None:
36
- super().__init__(context)
37
- def format_dataframe(self,result):
38
- st.dataframe(result['value'])
39
- return
40
- def format_plot(self,result):
41
- st.image(result['value'])
42
- return
43
- def format_other(self, result):
44
- st.write(result['value'])
45
- return
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  gemini_api_key = os.environ['Gemini']
48
 
@@ -94,11 +105,9 @@ def bot():
94
 
95
  lake = SmartDatalake([inventory_df, sales_df], config={"llm":llm, "response_parser":FlaskResponse, "enable_cache": False, "save_logs":False})
96
  response = lake.chat(user_question)
97
- resp = str(response)
98
  print(user_question)
99
 
100
- print(resp)
101
- return jsonify(resp)
102
 
103
 
104
  if __name__ == "__main__":
 
32
  cors = CORS(app)
33
 
34
  class FlaskResponse(ResponseParser):
35
+ def __init__(self, context) -> None:
36
+ super().__init__(context)
37
+
38
+ def format_dataframe(self, result):
39
+ return result['value'].to_html()
40
+
41
+ def format_plot(self, result):
42
+ # Save the plot using savefig
43
+ try:
44
+
45
+ img_path = result['value']
46
+
47
+
48
+ except ValueError:
49
+ img_path = str(result['value'])
50
+ print("value error!", img_path)
51
+
52
+ print("response_class_path:", img_path)
53
+ return img_path
54
+
55
+ def format_other(self, result):
56
+ return str(result['value'])
57
 
58
  gemini_api_key = os.environ['Gemini']
59
 
 
105
 
106
  lake = SmartDatalake([inventory_df, sales_df], config={"llm":llm, "response_parser":FlaskResponse, "enable_cache": False, "save_logs":False})
107
  response = lake.chat(user_question)
 
108
  print(user_question)
109
 
110
+ return jsonify(response)
 
111
 
112
 
113
  if __name__ == "__main__":