SVashishta1
commited on
Commit
·
fbbf665
1
Parent(s):
b43aa0c
Error Fix
Browse files
app.py
CHANGED
|
@@ -122,21 +122,25 @@ def process_text_query(query, history):
|
|
| 122 |
context = f"The database contains the following tables:\n" + "\n".join(table_info)
|
| 123 |
response = document_assistant.process_query(f"{context}\n\nUser query: {query}")
|
| 124 |
|
| 125 |
-
# Update history
|
| 126 |
-
history.append(
|
|
|
|
| 127 |
else:
|
| 128 |
# No tables found
|
| 129 |
-
history.append(
|
|
|
|
| 130 |
|
| 131 |
conn.close()
|
| 132 |
except Exception as e:
|
| 133 |
# Fall back to regular document query
|
| 134 |
response = document_assistant.process_query(query)
|
| 135 |
-
history.append(
|
|
|
|
| 136 |
else:
|
| 137 |
# Process regular document query
|
| 138 |
response = document_assistant.process_query(query)
|
| 139 |
-
history.append(
|
|
|
|
| 140 |
|
| 141 |
return "", history
|
| 142 |
|
|
@@ -186,7 +190,17 @@ def process_voice_input(audio_path):
|
|
| 186 |
|
| 187 |
def text_to_speech_output(text):
|
| 188 |
"""Convert text to speech"""
|
| 189 |
-
if not text:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
return None
|
| 191 |
|
| 192 |
# Since we don't have VoiceAssistant, return None
|
|
|
|
| 122 |
context = f"The database contains the following tables:\n" + "\n".join(table_info)
|
| 123 |
response = document_assistant.process_query(f"{context}\n\nUser query: {query}")
|
| 124 |
|
| 125 |
+
# Update history with message format
|
| 126 |
+
history.append({"role": "user", "content": query})
|
| 127 |
+
history.append({"role": "assistant", "content": response})
|
| 128 |
else:
|
| 129 |
# No tables found
|
| 130 |
+
history.append({"role": "user", "content": query})
|
| 131 |
+
history.append({"role": "assistant", "content": "No CSV data has been uploaded yet. Please upload a CSV file first."})
|
| 132 |
|
| 133 |
conn.close()
|
| 134 |
except Exception as e:
|
| 135 |
# Fall back to regular document query
|
| 136 |
response = document_assistant.process_query(query)
|
| 137 |
+
history.append({"role": "user", "content": query})
|
| 138 |
+
history.append({"role": "assistant", "content": response})
|
| 139 |
else:
|
| 140 |
# Process regular document query
|
| 141 |
response = document_assistant.process_query(query)
|
| 142 |
+
history.append({"role": "user", "content": query})
|
| 143 |
+
history.append({"role": "assistant", "content": response})
|
| 144 |
|
| 145 |
return "", history
|
| 146 |
|
|
|
|
| 190 |
|
| 191 |
def text_to_speech_output(text):
|
| 192 |
"""Convert text to speech"""
|
| 193 |
+
if not text or len(text) == 0:
|
| 194 |
+
return None
|
| 195 |
+
|
| 196 |
+
# Extract the last assistant message
|
| 197 |
+
last_message = None
|
| 198 |
+
for msg in reversed(text):
|
| 199 |
+
if msg["role"] == "assistant":
|
| 200 |
+
last_message = msg["content"]
|
| 201 |
+
break
|
| 202 |
+
|
| 203 |
+
if not last_message:
|
| 204 |
return None
|
| 205 |
|
| 206 |
# Since we don't have VoiceAssistant, return None
|