Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -168,7 +168,6 @@ import uuid
|
|
| 168 |
def generate_unique_id():
|
| 169 |
return str(uuid.uuid4())
|
| 170 |
|
| 171 |
-
|
| 172 |
def save_or_clone_to_cosmos_db(container, query=None, response=None, clone_id=None):
|
| 173 |
try:
|
| 174 |
if not container:
|
|
@@ -217,6 +216,7 @@ def save_or_clone_to_cosmos_db(container, query=None, response=None, clone_id=No
|
|
| 217 |
except Exception as e:
|
| 218 |
st.error(f"An unexpected error occurred: {str(e)}")
|
| 219 |
|
|
|
|
| 220 |
# Add dropdowns for model and database choices
|
| 221 |
def search_glossary(query):
|
| 222 |
st.markdown(f"### ๐ Search Glossary for: `{query}`")
|
|
@@ -449,10 +449,6 @@ def main():
|
|
| 449 |
st.title("๐Git๐Cosmos๐ซ - Azure Cosmos DB and Github Agent")
|
| 450 |
|
| 451 |
# Initialize session state
|
| 452 |
-
if 'logged_in' not in st.session_state:
|
| 453 |
-
st.session_state.logged_in = False
|
| 454 |
-
if 'selected_records' not in st.session_state:
|
| 455 |
-
st.session_state.selected_records = []
|
| 456 |
if 'client' not in st.session_state:
|
| 457 |
st.session_state.client = None
|
| 458 |
if 'selected_database' not in st.session_state:
|
|
@@ -463,19 +459,68 @@ def main():
|
|
| 463 |
st.session_state.selected_document_id = None
|
| 464 |
if 'current_index' not in st.session_state:
|
| 465 |
st.session_state.current_index = 0
|
| 466 |
-
if '
|
| 467 |
-
st.session_state.
|
| 468 |
|
| 469 |
-
#
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
# Automatic Login
|
| 481 |
if Key:
|
|
@@ -847,6 +892,19 @@ def main():
|
|
| 847 |
except Exception as e:
|
| 848 |
st.error(f"An unexpected error occurred: {str(e)} ๐ฑ")
|
| 849 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 850 |
# Logout button
|
| 851 |
if st.session_state.logged_in and st.sidebar.button("๐ช Logout"):
|
| 852 |
st.session_state.logged_in = False
|
|
|
|
| 168 |
def generate_unique_id():
|
| 169 |
return str(uuid.uuid4())
|
| 170 |
|
|
|
|
| 171 |
def save_or_clone_to_cosmos_db(container, query=None, response=None, clone_id=None):
|
| 172 |
try:
|
| 173 |
if not container:
|
|
|
|
| 216 |
except Exception as e:
|
| 217 |
st.error(f"An unexpected error occurred: {str(e)}")
|
| 218 |
|
| 219 |
+
|
| 220 |
# Add dropdowns for model and database choices
|
| 221 |
def search_glossary(query):
|
| 222 |
st.markdown(f"### ๐ Search Glossary for: `{query}`")
|
|
|
|
| 449 |
st.title("๐Git๐Cosmos๐ซ - Azure Cosmos DB and Github Agent")
|
| 450 |
|
| 451 |
# Initialize session state
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
if 'client' not in st.session_state:
|
| 453 |
st.session_state.client = None
|
| 454 |
if 'selected_database' not in st.session_state:
|
|
|
|
| 459 |
st.session_state.selected_document_id = None
|
| 460 |
if 'current_index' not in st.session_state:
|
| 461 |
st.session_state.current_index = 0
|
| 462 |
+
if 'documents' not in st.session_state:
|
| 463 |
+
st.session_state.documents = []
|
| 464 |
|
| 465 |
+
# Cosmos DB Connection (assuming this is done earlier in your code)
|
| 466 |
+
if st.session_state.client is None:
|
| 467 |
+
st.session_state.client = CosmosClient(ENDPOINT, credential=st.session_state.primary_key)
|
| 468 |
+
|
| 469 |
+
# Database and Container Selection
|
| 470 |
+
databases = get_databases(st.session_state.client)
|
| 471 |
+
selected_db = st.sidebar.selectbox("๐๏ธ Select Database", databases)
|
| 472 |
+
|
| 473 |
+
if selected_db != st.session_state.selected_database:
|
| 474 |
+
st.session_state.selected_database = selected_db
|
| 475 |
+
st.session_state.selected_container = None
|
| 476 |
+
st.session_state.selected_document_id = None
|
| 477 |
+
st.session_state.current_index = 0
|
| 478 |
+
st.rerun()
|
| 479 |
+
|
| 480 |
+
if st.session_state.selected_database:
|
| 481 |
+
database = st.session_state.client.get_database_client(st.session_state.selected_database)
|
| 482 |
+
containers = get_containers(database)
|
| 483 |
+
selected_container = st.sidebar.selectbox("๐ Select Container", containers)
|
| 484 |
+
|
| 485 |
+
if selected_container != st.session_state.selected_container:
|
| 486 |
+
st.session_state.selected_container = selected_container
|
| 487 |
+
st.session_state.selected_document_id = None
|
| 488 |
+
st.session_state.current_index = 0
|
| 489 |
+
st.rerun()
|
| 490 |
+
|
| 491 |
+
if st.session_state.selected_container:
|
| 492 |
+
container = database.get_container_client(st.session_state.selected_container)
|
| 493 |
+
|
| 494 |
+
# Add Export button
|
| 495 |
+
if st.button("๐ฆ Export Container Data"):
|
| 496 |
+
download_link = archive_current_container(st.session_state.selected_database, st.session_state.selected_container, st.session_state.client)
|
| 497 |
+
if download_link.startswith('<a'):
|
| 498 |
+
st.markdown(download_link, unsafe_allow_html=True)
|
| 499 |
+
else:
|
| 500 |
+
st.error(download_link)
|
| 501 |
+
|
| 502 |
+
# Fetch documents
|
| 503 |
+
st.session_state.documents = get_documents(container)
|
| 504 |
+
total_docs = len(st.session_state.documents)
|
| 505 |
+
|
| 506 |
+
# Add buttons for saving new document and cloning
|
| 507 |
+
if st.button("๐พ Save New Document"):
|
| 508 |
+
user_query = st.session_state.get('user_query', '')
|
| 509 |
+
ai_response = st.session_state.get('ai_response', '')
|
| 510 |
+
save_or_clone_to_cosmos_db(container, query=user_query, response=ai_response)
|
| 511 |
+
|
| 512 |
+
if st.button("๐ Clone Document"):
|
| 513 |
+
doc_to_clone = st.selectbox("Select document to clone", [doc['id'] for doc in st.session_state.documents])
|
| 514 |
+
if doc_to_clone:
|
| 515 |
+
save_or_clone_to_cosmos_db(container, clone_id=doc_to_clone)
|
| 516 |
+
|
| 517 |
+
# Display documents
|
| 518 |
+
if st.session_state.documents:
|
| 519 |
+
for doc in st.session_state.documents:
|
| 520 |
+
st.write(f"ID: {doc['id']}")
|
| 521 |
+
st.write(f"Query: {doc.get('query', 'N/A')}")
|
| 522 |
+
st.write(f"Response: {doc.get('response', 'N/A')}")
|
| 523 |
+
st.write("---")
|
| 524 |
|
| 525 |
# Automatic Login
|
| 526 |
if Key:
|
|
|
|
| 892 |
except Exception as e:
|
| 893 |
st.error(f"An unexpected error occurred: {str(e)} ๐ฑ")
|
| 894 |
|
| 895 |
+
|
| 896 |
+
# โ๏ธ q= Run ArXiv search from query parameters
|
| 897 |
+
try:
|
| 898 |
+
query_params = st.query_params
|
| 899 |
+
query = query_params.get('q') or query_params.get('query') or ''
|
| 900 |
+
if query:
|
| 901 |
+
# ๐ต๏ธโโ๏ธ We have a query! Let's process it!
|
| 902 |
+
process_text(query)
|
| 903 |
+
#st.stop() # Stop further execution
|
| 904 |
+
except Exception as e:
|
| 905 |
+
st.markdown(' ')
|
| 906 |
+
|
| 907 |
+
|
| 908 |
# Logout button
|
| 909 |
if st.session_state.logged_in and st.sidebar.button("๐ช Logout"):
|
| 910 |
st.session_state.logged_in = False
|