Update main.py
Browse files
main.py
CHANGED
|
@@ -32,17 +32,28 @@ app = Flask(__name__)
|
|
| 32 |
cors = CORS(app)
|
| 33 |
|
| 34 |
class FlaskResponse(ResponseParser):
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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__":
|