Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -178,6 +178,21 @@ def save_to_cosmos_db(container, query, response1, response2):
|
|
| 178 |
unique_uuid = str(uuid.uuid4())
|
| 179 |
return f"{timestamp}-{unique_uuid}"
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
for attempt in range(max_retries):
|
| 182 |
try:
|
| 183 |
if container:
|
|
@@ -205,6 +220,13 @@ def save_to_cosmos_db(container, query, response1, response2):
|
|
| 205 |
query="SELECT * FROM c ORDER BY c._ts DESC",
|
| 206 |
enable_cross_partition_query=True
|
| 207 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
return
|
| 209 |
else:
|
| 210 |
st.error("Cosmos DB container is not initialized.")
|
|
@@ -223,8 +245,6 @@ def save_to_cosmos_db(container, query, response1, response2):
|
|
| 223 |
|
| 224 |
st.error("Failed to save record after maximum retries.")
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
# Add dropdowns for model and database choices
|
| 229 |
def search_glossary(query):
|
| 230 |
st.markdown(f"### 🔍 Search Glossary for: `{query}`")
|
|
|
|
| 178 |
unique_uuid = str(uuid.uuid4())
|
| 179 |
return f"{timestamp}-{unique_uuid}"
|
| 180 |
|
| 181 |
+
def generate_short_filename(query):
|
| 182 |
+
# Create a hash of the query
|
| 183 |
+
hash_object = hashlib.md5(query.encode())
|
| 184 |
+
query_hash = hash_object.hexdigest()[:8]
|
| 185 |
+
|
| 186 |
+
# Use the first few words of the query (up to 50 characters)
|
| 187 |
+
short_query = ' '.join(query.split()[:5])[:50]
|
| 188 |
+
|
| 189 |
+
# Remove any non-alphanumeric characters and replace spaces with underscores
|
| 190 |
+
safe_query = ''.join(c if c.isalnum() else '_' for c in short_query)
|
| 191 |
+
|
| 192 |
+
# Combine timestamp, hash, and safe query
|
| 193 |
+
timestamp = datetime.utcnow().strftime('%Y%m%d%H%M%S')
|
| 194 |
+
return f"{timestamp}_{query_hash}_{safe_query}.md"
|
| 195 |
+
|
| 196 |
for attempt in range(max_retries):
|
| 197 |
try:
|
| 198 |
if container:
|
|
|
|
| 220 |
query="SELECT * FROM c ORDER BY c._ts DESC",
|
| 221 |
enable_cross_partition_query=True
|
| 222 |
)
|
| 223 |
+
|
| 224 |
+
# Generate a short filename for local storage
|
| 225 |
+
filename = generate_short_filename(query)
|
| 226 |
+
with open(filename, 'w', encoding='utf-8') as file:
|
| 227 |
+
file.write(f"Query: {query}\n\nResponse: {response1}")
|
| 228 |
+
st.success(f"File saved locally as: {filename}")
|
| 229 |
+
|
| 230 |
return
|
| 231 |
else:
|
| 232 |
st.error("Cosmos DB container is not initialized.")
|
|
|
|
| 245 |
|
| 246 |
st.error("Failed to save record after maximum retries.")
|
| 247 |
|
|
|
|
|
|
|
| 248 |
# Add dropdowns for model and database choices
|
| 249 |
def search_glossary(query):
|
| 250 |
st.markdown(f"### 🔍 Search Glossary for: `{query}`")
|