Update app.py
Browse files
app.py
CHANGED
@@ -102,10 +102,48 @@ class CSVChatApp:
|
|
102 |
else:
|
103 |
return "No CSV files were uploaded."
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
def process_query(self, query, history):
|
106 |
"""Process a user query and generate a response."""
|
107 |
if not self.uploaded_files:
|
108 |
-
|
|
|
109 |
|
110 |
# Add user message to history
|
111 |
self.chat_history.append({"role": "user", "content": query})
|
@@ -130,12 +168,16 @@ class CSVChatApp:
|
|
130 |
# Add assistant message to history
|
131 |
self.chat_history.append({"role": "assistant", "content": answer})
|
132 |
|
133 |
-
|
|
|
134 |
|
135 |
except Exception as e:
|
136 |
error_msg = f"Error processing query: {str(e)}"
|
137 |
self.chat_history.append({"role": "assistant", "content": error_msg})
|
138 |
-
|
|
|
|
|
|
|
139 |
|
140 |
def export_conversation(self):
|
141 |
"""Export the conversation as a report."""
|
|
|
102 |
else:
|
103 |
return "No CSV files were uploaded."
|
104 |
|
105 |
+
# def process_query(self, query, history):
|
106 |
+
# """Process a user query and generate a response."""
|
107 |
+
# if not self.uploaded_files:
|
108 |
+
# return "Please upload CSV files before asking questions."
|
109 |
+
|
110 |
+
# # Add user message to history
|
111 |
+
# self.chat_history.append({"role": "user", "content": query})
|
112 |
+
|
113 |
+
# # Process the query
|
114 |
+
# try:
|
115 |
+
# response = self.query_engine.query(query)
|
116 |
+
# answer = response["answer"]
|
117 |
+
|
118 |
+
# # Check if response contains an image
|
119 |
+
# if isinstance(answer, dict) and "image" in answer:
|
120 |
+
# # Handle image in response
|
121 |
+
# img_data = answer["image"]
|
122 |
+
# img = Image.open(io.BytesIO(base64.b64decode(img_data)))
|
123 |
+
# img_path = EXPORT_DIR / f"viz_{int(time.time())}.png"
|
124 |
+
# img.save(img_path)
|
125 |
+
|
126 |
+
# # Update answer to include image path
|
127 |
+
# text_response = answer.get("text", "Generated visualization")
|
128 |
+
# answer = (text_response, str(img_path))
|
129 |
+
|
130 |
+
# # Add assistant message to history
|
131 |
+
# self.chat_history.append({"role": "assistant", "content": answer})
|
132 |
+
|
133 |
+
# return answer
|
134 |
+
|
135 |
+
# except Exception as e:
|
136 |
+
# error_msg = f"Error processing query: {str(e)}"
|
137 |
+
# self.chat_history.append({"role": "assistant", "content": error_msg})
|
138 |
+
# return error_msg
|
139 |
+
|
140 |
+
# In app.py, modify the process_query method:
|
141 |
+
|
142 |
def process_query(self, query, history):
|
143 |
"""Process a user query and generate a response."""
|
144 |
if not self.uploaded_files:
|
145 |
+
# Return in the correct format for the chatbot
|
146 |
+
return history + [[query, "Please upload CSV files before asking questions."]]
|
147 |
|
148 |
# Add user message to history
|
149 |
self.chat_history.append({"role": "user", "content": query})
|
|
|
168 |
# Add assistant message to history
|
169 |
self.chat_history.append({"role": "assistant", "content": answer})
|
170 |
|
171 |
+
# Return in the correct format for the chatbot
|
172 |
+
return history + [[query, answer]]
|
173 |
|
174 |
except Exception as e:
|
175 |
error_msg = f"Error processing query: {str(e)}"
|
176 |
self.chat_history.append({"role": "assistant", "content": error_msg})
|
177 |
+
|
178 |
+
# Return in the correct format for the chatbot
|
179 |
+
return history + [[query, error_msg]]
|
180 |
+
|
181 |
|
182 |
def export_conversation(self):
|
183 |
"""Export the conversation as a report."""
|