Spaces:
Sleeping
Sleeping
Added updated intent
Browse files- main.py +17 -2
- rag/sql_db.py +2 -2
main.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
# main.py
|
2 |
import asyncio
|
3 |
import importlib
|
|
|
|
|
4 |
from voice.speech_to_text import SpeechToText
|
5 |
from voice.intent_classifier import IntentClassifier
|
6 |
# from voice.classifier import TextClassifier
|
@@ -111,7 +113,7 @@ async def process_query(vosk_model_path, audio_data=None, query_text=None, use_r
|
|
111 |
output["retriever_response"] = retriever_response
|
112 |
else:
|
113 |
# Base response failed, use the retriever
|
114 |
-
output["base_response"] = f"{base_response}
|
115 |
# retriever_response = retriever.retrieve(text, entities)
|
116 |
# retriever_response = sql_db.keyword_match_search(entities)
|
117 |
retriever_response = sql_db.query_db(entities["ticker"], entities["metric"])
|
@@ -144,6 +146,19 @@ async def process_query(vosk_model_path, audio_data=None, query_text=None, use_r
|
|
144 |
except Exception as e:
|
145 |
output["error"] = f"Unexpected error: {e}"
|
146 |
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
# Return output to the User Interface
|
149 |
return output
|
|
|
1 |
# main.py
|
2 |
import asyncio
|
3 |
import importlib
|
4 |
+
from datetime import datetime
|
5 |
+
import requests
|
6 |
from voice.speech_to_text import SpeechToText
|
7 |
from voice.intent_classifier import IntentClassifier
|
8 |
# from voice.classifier import TextClassifier
|
|
|
113 |
output["retriever_response"] = retriever_response
|
114 |
else:
|
115 |
# Base response failed, use the retriever
|
116 |
+
output["base_response"] = f"{base_response} Using retriever to query CSV file..."
|
117 |
# retriever_response = retriever.retrieve(text, entities)
|
118 |
# retriever_response = sql_db.keyword_match_search(entities)
|
119 |
retriever_response = sql_db.query_db(entities["ticker"], entities["metric"])
|
|
|
146 |
except Exception as e:
|
147 |
output["error"] = f"Unexpected error: {e}"
|
148 |
|
149 |
+
|
150 |
+
# Current Time
|
151 |
+
now = datetime.now()
|
152 |
+
print("Current Time:", now.strftime("%Y-%m-%d %H:%M:%S"))
|
153 |
+
|
154 |
+
# Location Info
|
155 |
+
try:
|
156 |
+
response = requests.get("https://ipinfo.io")
|
157 |
+
data = response.json()
|
158 |
+
print("Location:", data.get("city"), data.get("region"), data.get("country"))
|
159 |
+
|
160 |
+
except Exception as e:
|
161 |
+
print("Could not fetch location:", e)
|
162 |
+
|
163 |
# Return output to the User Interface
|
164 |
return output
|
rag/sql_db.py
CHANGED
@@ -166,7 +166,7 @@ class SQL_Key_Pair:
|
|
166 |
if result:
|
167 |
value = result[0]
|
168 |
value_in_billions = value / 1_000_000_000
|
169 |
-
return f"{metric} for {ticker}: ${value_in_billions:.2f} billion."
|
170 |
return f"No relevant data found for {ticker}."
|
171 |
except Exception as e:
|
172 |
print(f"Error querying database: {e}")
|
@@ -176,6 +176,6 @@ class SQL_Key_Pair:
|
|
176 |
try:
|
177 |
if hasattr(self, 'db_conn') and self.db_conn:
|
178 |
self.db_conn.close()
|
179 |
-
print("Closed SQLite database connection")
|
180 |
except Exception as e:
|
181 |
print(f"Error closing database connection: {e}")
|
|
|
166 |
if result:
|
167 |
value = result[0]
|
168 |
value_in_billions = value / 1_000_000_000
|
169 |
+
return f"The {metric} for {ticker} was : ${value_in_billions:.2f} billion in 2024."
|
170 |
return f"No relevant data found for {ticker}."
|
171 |
except Exception as e:
|
172 |
print(f"Error querying database: {e}")
|
|
|
176 |
try:
|
177 |
if hasattr(self, 'db_conn') and self.db_conn:
|
178 |
self.db_conn.close()
|
179 |
+
# print("Closed SQLite database connection")
|
180 |
except Exception as e:
|
181 |
print(f"Error closing database connection: {e}")
|