awacke1 commited on
Commit
3c303ad
Β·
verified Β·
1 Parent(s): a59b8d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -124
app.py CHANGED
@@ -1,6 +1,4 @@
1
- # =============================================================================
2
- # ───────────── IMPORTS ─────────────
3
- # =============================================================================
4
  import base64
5
  import glob
6
  import hashlib
@@ -28,9 +26,7 @@ import requests
28
  import numpy as np
29
  from urllib.parse import quote
30
 
31
- # =============================================================================
32
- # ───────────── EXTERNAL HELP LINKS (Always visible in sidebar) ─────────────
33
- # =============================================================================
34
  external_links = [
35
  {"title": "CosmosDB GenAI Full Text Search", "url": "https://learn.microsoft.com/en-us/azure/cosmos-db/gen-ai/full-text-search", "emoji": "πŸ’»"},
36
  {"title": "CosmosDB SQL API Client Library", "url": "https://learn.microsoft.com/en-us/python/api/overview/azure/cosmos-readme?view=azure-python", "emoji": "πŸ’»"},
@@ -45,9 +41,7 @@ external_links = [
45
  {"title": "arcee.ai Official Website", "url": "https://arcee.ai", "emoji": "🌐"},
46
  ]
47
 
48
- # =============================================================================
49
- # ───────────── APP CONFIGURATION ─────────────
50
- # =============================================================================
51
  Site_Name = 'πŸ™ GitCosmos'
52
  title = "πŸ™ GitCosmos"
53
  helpURL = 'https://huggingface.co/awacke1'
@@ -65,7 +59,7 @@ st.set_page_config(
65
  }
66
  )
67
 
68
- # Cosmos DB & App URLs
69
  ENDPOINT = "https://acae-afd.documents.azure.com:443/"
70
  DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
71
  CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
@@ -73,9 +67,7 @@ Key = os.environ.get("Key")
73
  LOCAL_APP_URL = "https://huggingface.co/spaces/awacke1/AzureCosmosDBUI"
74
  CosmosDBUrl = 'https://portal.azure.com/#@AaronCWackergmail.onmicrosoft.com/resource/subscriptions/003fba60-5b3f-48f4-ab36-3ed11bc40816/resourceGroups/datasets/providers/Microsoft.DocumentDB/databaseAccounts/acae-afd/dataExplorer'
75
 
76
- # =============================================================================
77
- # ───────────── HELPER FUNCTIONS ─────────────
78
- # =============================================================================
79
  def get_download_link(file_path):
80
  with open(file_path, "rb") as file:
81
  contents = file.read()
@@ -154,9 +146,7 @@ def sanitize_json_text(text):
154
  text = text.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t")
155
  return text
156
 
157
- # =============================================================================
158
- # ───────────── COSMOS DB FUNCTIONS ─────────────
159
- # =============================================================================
160
  def get_databases(client):
161
  return [db['id'] for db in client.list_databases()]
162
 
@@ -222,29 +212,19 @@ def archive_current_container(database_name, container_name, client):
222
  except Exception as e:
223
  return f"Archive error: {str(e)} 😒"
224
 
225
- # =============================================================================
226
- # ───────────── ADVANCED COSMOS FUNCTIONS ─────────────
227
  # (Include your advanced Cosmos functions here if needed)
228
- # =============================================================================
229
- # For example, you might have functions like:
230
- # def create_new_container(...):
231
- # ...
232
-
233
- # =============================================================================
234
- # ───────────── NEW COSMOSDB DEMO FUNCTIONS ─────────────
235
- # Each function below corresponds to one of your provided code snippets.
236
- # =============================================================================
237
 
 
238
  def demo_create_database():
239
  st.markdown("### Demo: Create Database")
240
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_name")
241
  if st.button("Create Database", key="btn_create_db"):
242
- url = os.environ.get("ACCOUNT_URI")
243
- key_env = os.environ.get("ACCOUNT_KEY")
244
- if not url or not key_env:
245
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
246
  return
247
- client_demo = CosmosClient(url, credential=key_env)
248
  try:
249
  database = client_demo.create_database(database_name)
250
  st.success(f"Database '{database_name}' created.")
@@ -262,12 +242,10 @@ def demo_create_container():
262
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_name")
263
  partition_key = st.text_input("Enter Partition Key Path", value="/productName", key="demo_partition_key")
264
  if st.button("Create Container", key="btn_create_container"):
265
- url = os.environ.get("ACCOUNT_URI")
266
- key_env = os.environ.get("ACCOUNT_KEY")
267
- if not url or not key_env:
268
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
269
  return
270
- client_demo = CosmosClient(url, credential=key_env)
271
  try:
272
  database = client_demo.get_database_client(database_name)
273
  container = database.create_container(id=container_name, partition_key=PartitionKey(path=partition_key))
@@ -288,12 +266,10 @@ def demo_create_analytical_container():
288
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_analytical")
289
  partition_key = st.text_input("Enter Partition Key Path", value="/productName", key="demo_partition_key_analytical")
290
  if st.button("Create Analytical Container", key="btn_create_analytical"):
291
- url = os.environ.get("ACCOUNT_URI")
292
- key_env = os.environ.get("ACCOUNT_KEY")
293
- if not url or not key_env:
294
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
295
  return
296
- client_demo = CosmosClient(url, credential=key_env)
297
  try:
298
  database = client_demo.get_database_client(database_name)
299
  container = database.create_container(
@@ -317,12 +293,10 @@ def demo_get_existing_container():
317
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_get")
318
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_get")
319
  if st.button("Get Container", key="btn_get_container"):
320
- url = os.environ.get("ACCOUNT_URI")
321
- key_env = os.environ.get("ACCOUNT_KEY")
322
- if not url or not key_env:
323
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
324
  return
325
- client_demo = CosmosClient(url, credential=key_env)
326
  try:
327
  database = client_demo.get_database_client(database_name)
328
  container = database.get_container_client(container_name)
@@ -337,12 +311,10 @@ def demo_insert_data():
337
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_insert")
338
  num_items = st.number_input("Number of items to insert", min_value=1, max_value=20, value=9, key="demo_num_items")
339
  if st.button("Insert Data", key="btn_insert_data"):
340
- url = os.environ.get("ACCOUNT_URI")
341
- key_env = os.environ.get("ACCOUNT_KEY")
342
- if not url or not key_env:
343
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
344
  return
345
- client_demo = CosmosClient(url, credential=key_env)
346
  try:
347
  database = client_demo.get_database_client(database_name)
348
  container = database.get_container_client(container_name)
@@ -362,12 +334,10 @@ def demo_delete_data():
362
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_delete")
363
  query_model = st.text_input("Product Model to delete", value="Model 2", key="demo_query_model")
364
  if st.button("Delete Data", key="btn_delete_data"):
365
- url = os.environ.get("ACCOUNT_URI")
366
- key_env = os.environ.get("ACCOUNT_KEY")
367
- if not url or not key_env:
368
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
369
  return
370
- client_demo = CosmosClient(url, credential=key_env)
371
  try:
372
  database = client_demo.get_database_client(database_name)
373
  container = database.get_container_client(container_name)
@@ -389,12 +359,10 @@ def demo_query_database():
389
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_query")
390
  query_str = st.text_area("Enter SQL Query", value='SELECT * FROM mycontainer r WHERE r.id="item3"', key="demo_query_str")
391
  if st.button("Run Query", key="btn_query_database"):
392
- url = os.environ.get("ACCOUNT_URI")
393
- key_env = os.environ.get("ACCOUNT_KEY")
394
- if not url or not key_env:
395
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
396
  return
397
- client_demo = CosmosClient(url, credential=key_env)
398
  try:
399
  database = client_demo.get_database_client(database_name)
400
  container = database.get_container_client(container_name)
@@ -413,12 +381,10 @@ def demo_parameterized_query():
413
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_param")
414
  model_value = st.text_input("Enter productModel value", value="Model 7", key="demo_model_value")
415
  if st.button("Run Parameterized Query", key="btn_param_query"):
416
- url = os.environ.get("ACCOUNT_URI")
417
- key_env = os.environ.get("ACCOUNT_KEY")
418
- if not url or not key_env:
419
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
420
  return
421
- client_demo = CosmosClient(url, credential=key_env)
422
  try:
423
  database = client_demo.get_database_client(database_name)
424
  container = database.get_container_client(container_name)
@@ -436,12 +402,10 @@ def demo_get_db_properties():
436
  st.markdown("### Demo: Get Database Properties")
437
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_props")
438
  if st.button("Get Properties", key="btn_db_props"):
439
- url = os.environ.get("ACCOUNT_URI")
440
- key_env = os.environ.get("ACCOUNT_KEY")
441
- if not url or not key_env:
442
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
443
  return
444
- client_demo = CosmosClient(url, credential=key_env)
445
  try:
446
  database = client_demo.get_database_client(database_name)
447
  props = database.read()
@@ -454,12 +418,10 @@ def demo_get_throughput():
454
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_throughput")
455
  container_name = st.text_input("Enter Container Name (for container throughput)", value="testContainer", key="demo_container_throughput")
456
  if st.button("Get Throughput", key="btn_get_throughput"):
457
- url = os.environ.get("ACCOUNT_URI")
458
- key_env = os.environ.get("ACCOUNT_KEY")
459
- if not url or not key_env:
460
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
461
  return
462
- client_demo = CosmosClient(url, credential=key_env)
463
  try:
464
  database = client_demo.get_database_client(database_name)
465
  db_offer = database.get_throughput()
@@ -479,16 +441,14 @@ def demo_modify_container_properties():
479
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_modify")
480
  new_ttl = st.number_input("Enter new default TTL (seconds)", min_value=0, value=10, key="demo_new_ttl")
481
  if st.button("Modify Container", key="btn_modify_container"):
482
- url = os.environ.get("ACCOUNT_URI")
483
- key_env = os.environ.get("ACCOUNT_KEY")
484
- if not url or not key_env:
485
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
486
  return
487
- client_demo = CosmosClient(url, credential=key_env)
488
  try:
489
  database = client_demo.get_database_client(database_name)
490
  container = database.get_container_client(container_name)
491
- # Note: replace_container is used here as per your snippet.
492
  database.replace_container(
493
  container,
494
  partition_key=PartitionKey(path="/productName"),
@@ -504,12 +464,10 @@ def demo_item_response_headers():
504
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_headers")
505
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_headers")
506
  if st.button("Create Item & Show Headers", key="btn_item_headers"):
507
- url = os.environ.get("ACCOUNT_URI")
508
- key_env = os.environ.get("ACCOUNT_KEY")
509
- if not url or not key_env:
510
- st.error("Missing ACCOUNT_URI or ACCOUNT_KEY environment variables.")
511
  return
512
- client_demo = CosmosClient(url, credential=key_env)
513
  try:
514
  database = client_demo.get_database_client(database_name)
515
  container = database.get_container_client(container_name)
@@ -520,9 +478,7 @@ def demo_item_response_headers():
520
  except Exception as e:
521
  st.error(f"Error: {str(e)}")
522
 
523
- # =============================================================================
524
- # ───────────── FILE & MEDIA MANAGEMENT FUNCTIONS ─────────────
525
- # =============================================================================
526
  def display_saved_files_in_sidebar():
527
  all_files = sorted([f for f in glob.glob("*.md") if not f.lower().startswith('readme')], reverse=True)
528
  st.sidebar.markdown("## πŸ“ Files")
@@ -654,9 +610,7 @@ def update_file_management_section():
654
  elif st.session_state.file_view_mode == 'edit':
655
  display_file_editor(st.session_state.current_file)
656
 
657
- # =============================================================================
658
- # ───────────── SIDEBAR DATA GRID (Records with formatted timestamps) ─────────────
659
- # =============================================================================
660
  def show_sidebar_data_grid():
661
  if st.session_state.get("current_container"):
662
  try:
@@ -682,9 +636,7 @@ def show_sidebar_data_grid():
682
  else:
683
  st.sidebar.info("No container selected for data grid.")
684
 
685
- # =============================================================================
686
- # ───────────── DOCUMENTS LIST VIEW (Editable List with Sorting) ─────────────
687
- # =============================================================================
688
  def edit_documents_list(container):
689
  records = get_documents(container)
690
  sort_option = st.selectbox("Sort by", ["Timestamp", "Name"], key="sort_option")
@@ -724,9 +676,7 @@ def edit_documents_list(container):
724
  st.error(f"Error updating {doc_id}: {message}")
725
  st.rerun()
726
 
727
- # =============================================================================
728
- # ───────────── VIDEO & AUDIO UI FUNCTIONS ─────────────
729
- # =============================================================================
730
  def validate_and_preprocess_image(file_data, target_size=(576, 1024)):
731
  try:
732
  st.write("Preprocessing image...")
@@ -840,9 +790,7 @@ def add_video_generation_ui(container):
840
  except Exception as e:
841
  st.error(f"Upload error: {str(e)}")
842
 
843
- # =============================================================================
844
- # ───────────── NEW ITEM & FIELD FUNCTIONS ─────────────
845
- # =============================================================================
846
  def new_item_default(container):
847
  new_id = generate_unique_id()
848
  default_doc = {
@@ -887,9 +835,7 @@ def add_field_to_doc():
887
  except Exception as e:
888
  st.error(f"Error adding field: {str(e)}")
889
 
890
- # =============================================================================
891
- # ───────────── VECTOR SEARCH INTERFACE ─────────────
892
- # =============================================================================
893
  def vector_keyword_search(keyword, container):
894
  try:
895
  query = f"SELECT * FROM c WHERE CONTAINS(c.content, '{keyword}')"
@@ -916,9 +862,7 @@ def display_search_results(keyword, container):
916
  except Exception as e:
917
  st.error(f"Error saving {doc_id}: {str(e)}")
918
 
919
- # =============================================================================
920
- # ───────────── NEW AI MODALITY RECORD TEMPLATES ─────────────
921
- # =============================================================================
922
  def new_ai_record(container):
923
  new_id = generate_unique_id()
924
  default_doc = {
@@ -960,9 +904,7 @@ def new_links_record(container):
960
  st.error("Error creating links record: " + message)
961
  return None
962
 
963
- # =============================================================================
964
- # ───────────── SIDEBAR DATA GRID (Editable Names Grid) ─────────────
965
- # =============================================================================
966
  def edit_names_grid(container):
967
  records = get_documents(container)
968
  data = []
@@ -995,10 +937,7 @@ def edit_names_grid(container):
995
  st.sidebar.error(f"Update error for {doc_id}: {message}")
996
  st.rerun()
997
 
998
- # =============================================================================
999
- # ───────────── SEARCH DOCUMENTS UI ─────────────
1000
- # This function was missing and is now defined.
1001
- # =============================================================================
1002
  def search_documents_ui(container):
1003
  with st.sidebar.form("search_form"):
1004
  keyword = st.text_input("Search Keyword", key="search_keyword")
@@ -1006,9 +945,7 @@ def search_documents_ui(container):
1006
  if submitted and keyword:
1007
  display_search_results(keyword, container)
1008
 
1009
- # =============================================================================
1010
- # ───────────── MAIN FUNCTION ─────────────
1011
- # =============================================================================
1012
  def main():
1013
  st.markdown("### πŸ™ GitCosmos - Cosmos & Git Hub")
1014
  st.markdown(f"[πŸ”— Portal]({CosmosDBUrl})")
@@ -1022,7 +959,7 @@ def main():
1022
  st.error("Missing Cosmos Key πŸ”‘βŒ")
1023
  return
1024
 
1025
- # ── New: CosmosDB Demo Features Section in Sidebar ──
1026
  st.sidebar.markdown("## CosmosDB Demo Features")
1027
  demo_feature = st.sidebar.selectbox("Select a Demo",
1028
  ["Select", "Create Database", "Create Container", "Create Analytical Container",
@@ -1056,7 +993,7 @@ def main():
1056
  elif demo_feature == "Item Response Headers":
1057
  demo_item_response_headers()
1058
 
1059
- # ── Existing Sidebar Items (Item Management, File Management, etc.)
1060
  st.sidebar.markdown("## πŸ› οΈ Item Management")
1061
  if st.sidebar.button("New Item"):
1062
  if st.session_state.get("current_container"):
@@ -1086,7 +1023,7 @@ def main():
1086
  search_documents_ui(st.session_state.get("current_container"))
1087
  show_sidebar_data_grid()
1088
 
1089
- # (Your remaining navigation, file management, and document editing UI follow)
1090
  try:
1091
  if st.session_state.get("client") is None:
1092
  st.session_state.client = CosmosClient(ENDPOINT, credential=st.session_state.primary_key)
@@ -1113,7 +1050,7 @@ def main():
1113
  submitted = st.form_submit_button("Create Container")
1114
  if submitted:
1115
  analytical_ttl = -1 if new_analytical else None
1116
- # Assuming create_new_container is defined in your advanced functions:
1117
  new_container = database.create_container(
1118
  id=new_container_id,
1119
  partition_key=PartitionKey(path=new_partition_key),
@@ -1223,7 +1160,6 @@ def main():
1223
  ai_query = st.text_area("Enter your query for ArXiv search:", key="arxiv_query", height=100)
1224
  if st.button("Send"):
1225
  st.session_state.last_query = ai_query
1226
- # perform_ai_lookup would be your AI function call.
1227
  st.info("Performing AI lookup (function not implemented in this demo)...")
1228
  elif selected_view == 'Clone':
1229
  st.markdown("#### πŸ“„ Clone")
 
1
+ # πŸ“šπŸ“šπŸ“š IMPORTS πŸ“šπŸ“šπŸ“š
 
 
2
  import base64
3
  import glob
4
  import hashlib
 
26
  import numpy as np
27
  from urllib.parse import quote
28
 
29
+ # 🌐🌐🌐 EXTERNAL HELP LINKS (Always visible in sidebar) 🌐🌐🌐
 
 
30
  external_links = [
31
  {"title": "CosmosDB GenAI Full Text Search", "url": "https://learn.microsoft.com/en-us/azure/cosmos-db/gen-ai/full-text-search", "emoji": "πŸ’»"},
32
  {"title": "CosmosDB SQL API Client Library", "url": "https://learn.microsoft.com/en-us/python/api/overview/azure/cosmos-readme?view=azure-python", "emoji": "πŸ’»"},
 
41
  {"title": "arcee.ai Official Website", "url": "https://arcee.ai", "emoji": "🌐"},
42
  ]
43
 
44
+ # πŸš€πŸš€πŸš€ APP CONFIGURATION πŸš€πŸš€πŸš€
 
 
45
  Site_Name = 'πŸ™ GitCosmos'
46
  title = "πŸ™ GitCosmos"
47
  helpURL = 'https://huggingface.co/awacke1'
 
59
  }
60
  )
61
 
62
+ # 🌌🌌🌌 COSMOS DB & APP CONFIGURATION 🌌🌌🌌
63
  ENDPOINT = "https://acae-afd.documents.azure.com:443/"
64
  DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
65
  CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
 
67
  LOCAL_APP_URL = "https://huggingface.co/spaces/awacke1/AzureCosmosDBUI"
68
  CosmosDBUrl = 'https://portal.azure.com/#@AaronCWackergmail.onmicrosoft.com/resource/subscriptions/003fba60-5b3f-48f4-ab36-3ed11bc40816/resourceGroups/datasets/providers/Microsoft.DocumentDB/databaseAccounts/acae-afd/dataExplorer'
69
 
70
+ # πŸ”§πŸ”§πŸ”§ HELPER FUNCTIONS πŸ”§πŸ”§πŸ”§
 
 
71
  def get_download_link(file_path):
72
  with open(file_path, "rb") as file:
73
  contents = file.read()
 
146
  text = text.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t")
147
  return text
148
 
149
+ # 🌌🌌🌌 COSMOS DB FUNCTIONS 🌌🌌🌌
 
 
150
  def get_databases(client):
151
  return [db['id'] for db in client.list_databases()]
152
 
 
212
  except Exception as e:
213
  return f"Archive error: {str(e)} 😒"
214
 
215
+ # 🌠🌠🌠 ADVANCED COSMOS FUNCTIONS (if needed) 🌠🌠🌠
 
216
  # (Include your advanced Cosmos functions here if needed)
217
+ # For example, you might have functions like create_new_container(), etc.
 
 
 
 
 
 
 
 
218
 
219
+ # πŸŽ‰πŸŽ‰πŸŽ‰ NEW COSMOSDB DEMO FUNCTIONS (Using ENDPOINT and Key) πŸŽ‰πŸŽ‰πŸŽ‰
220
  def demo_create_database():
221
  st.markdown("### Demo: Create Database")
222
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_name")
223
  if st.button("Create Database", key="btn_create_db"):
224
+ if not ENDPOINT or not Key:
225
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
226
  return
227
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
228
  try:
229
  database = client_demo.create_database(database_name)
230
  st.success(f"Database '{database_name}' created.")
 
242
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_name")
243
  partition_key = st.text_input("Enter Partition Key Path", value="/productName", key="demo_partition_key")
244
  if st.button("Create Container", key="btn_create_container"):
245
+ if not ENDPOINT or not Key:
246
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
247
  return
248
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
249
  try:
250
  database = client_demo.get_database_client(database_name)
251
  container = database.create_container(id=container_name, partition_key=PartitionKey(path=partition_key))
 
266
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_analytical")
267
  partition_key = st.text_input("Enter Partition Key Path", value="/productName", key="demo_partition_key_analytical")
268
  if st.button("Create Analytical Container", key="btn_create_analytical"):
269
+ if not ENDPOINT or not Key:
270
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
271
  return
272
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
273
  try:
274
  database = client_demo.get_database_client(database_name)
275
  container = database.create_container(
 
293
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_get")
294
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_get")
295
  if st.button("Get Container", key="btn_get_container"):
296
+ if not ENDPOINT or not Key:
297
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
298
  return
299
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
300
  try:
301
  database = client_demo.get_database_client(database_name)
302
  container = database.get_container_client(container_name)
 
311
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_insert")
312
  num_items = st.number_input("Number of items to insert", min_value=1, max_value=20, value=9, key="demo_num_items")
313
  if st.button("Insert Data", key="btn_insert_data"):
314
+ if not ENDPOINT or not Key:
315
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
316
  return
317
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
318
  try:
319
  database = client_demo.get_database_client(database_name)
320
  container = database.get_container_client(container_name)
 
334
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_delete")
335
  query_model = st.text_input("Product Model to delete", value="Model 2", key="demo_query_model")
336
  if st.button("Delete Data", key="btn_delete_data"):
337
+ if not ENDPOINT or not Key:
338
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
339
  return
340
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
341
  try:
342
  database = client_demo.get_database_client(database_name)
343
  container = database.get_container_client(container_name)
 
359
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_query")
360
  query_str = st.text_area("Enter SQL Query", value='SELECT * FROM mycontainer r WHERE r.id="item3"', key="demo_query_str")
361
  if st.button("Run Query", key="btn_query_database"):
362
+ if not ENDPOINT or not Key:
363
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
364
  return
365
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
366
  try:
367
  database = client_demo.get_database_client(database_name)
368
  container = database.get_container_client(container_name)
 
381
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_param")
382
  model_value = st.text_input("Enter productModel value", value="Model 7", key="demo_model_value")
383
  if st.button("Run Parameterized Query", key="btn_param_query"):
384
+ if not ENDPOINT or not Key:
385
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
386
  return
387
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
388
  try:
389
  database = client_demo.get_database_client(database_name)
390
  container = database.get_container_client(container_name)
 
402
  st.markdown("### Demo: Get Database Properties")
403
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_props")
404
  if st.button("Get Properties", key="btn_db_props"):
405
+ if not ENDPOINT or not Key:
406
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
407
  return
408
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
409
  try:
410
  database = client_demo.get_database_client(database_name)
411
  props = database.read()
 
418
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_throughput")
419
  container_name = st.text_input("Enter Container Name (for container throughput)", value="testContainer", key="demo_container_throughput")
420
  if st.button("Get Throughput", key="btn_get_throughput"):
421
+ if not ENDPOINT or not Key:
422
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
423
  return
424
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
425
  try:
426
  database = client_demo.get_database_client(database_name)
427
  db_offer = database.get_throughput()
 
441
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_modify")
442
  new_ttl = st.number_input("Enter new default TTL (seconds)", min_value=0, value=10, key="demo_new_ttl")
443
  if st.button("Modify Container", key="btn_modify_container"):
444
+ if not ENDPOINT or not Key:
445
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
446
  return
447
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
448
  try:
449
  database = client_demo.get_database_client(database_name)
450
  container = database.get_container_client(container_name)
451
+ # Using replace_container as in your snippet.
452
  database.replace_container(
453
  container,
454
  partition_key=PartitionKey(path="/productName"),
 
464
  database_name = st.text_input("Enter Database Name", value="testDatabase", key="demo_db_headers")
465
  container_name = st.text_input("Enter Container Name", value="products", key="demo_container_headers")
466
  if st.button("Create Item & Show Headers", key="btn_item_headers"):
467
+ if not ENDPOINT or not Key:
468
+ st.error("Missing Cosmos configuration: ENDPOINT or Key")
 
 
469
  return
470
+ client_demo = CosmosClient(ENDPOINT, credential=Key)
471
  try:
472
  database = client_demo.get_database_client(database_name)
473
  container = database.get_container_client(container_name)
 
478
  except Exception as e:
479
  st.error(f"Error: {str(e)}")
480
 
481
+ # πŸ“πŸ“πŸ“ FILE & MEDIA MANAGEMENT FUNCTIONS πŸ“πŸ“πŸ“
 
 
482
  def display_saved_files_in_sidebar():
483
  all_files = sorted([f for f in glob.glob("*.md") if not f.lower().startswith('readme')], reverse=True)
484
  st.sidebar.markdown("## πŸ“ Files")
 
610
  elif st.session_state.file_view_mode == 'edit':
611
  display_file_editor(st.session_state.current_file)
612
 
613
+ # πŸ“ŠπŸ“ŠπŸ“Š SIDEBAR DATA GRID (Records with formatted timestamps) πŸ“ŠπŸ“ŠπŸ“Š
 
 
614
  def show_sidebar_data_grid():
615
  if st.session_state.get("current_container"):
616
  try:
 
636
  else:
637
  st.sidebar.info("No container selected for data grid.")
638
 
639
+ # πŸ“πŸ“πŸ“ DOCUMENTS LIST VIEW (Editable List with Sorting) πŸ“πŸ“πŸ“
 
 
640
  def edit_documents_list(container):
641
  records = get_documents(container)
642
  sort_option = st.selectbox("Sort by", ["Timestamp", "Name"], key="sort_option")
 
676
  st.error(f"Error updating {doc_id}: {message}")
677
  st.rerun()
678
 
679
+ # πŸŽ₯🎡πŸŽ₯ VIDEO & AUDIO UI FUNCTIONS πŸŽ₯🎡πŸŽ₯
 
 
680
  def validate_and_preprocess_image(file_data, target_size=(576, 1024)):
681
  try:
682
  st.write("Preprocessing image...")
 
790
  except Exception as e:
791
  st.error(f"Upload error: {str(e)}")
792
 
793
+ # βž•βž•βž• NEW ITEM & FIELD FUNCTIONS βž•βž•βž•
 
 
794
  def new_item_default(container):
795
  new_id = generate_unique_id()
796
  default_doc = {
 
835
  except Exception as e:
836
  st.error(f"Error adding field: {str(e)}")
837
 
838
+ # πŸ”πŸ”πŸ” VECTOR SEARCH INTERFACE πŸ”πŸ”πŸ”
 
 
839
  def vector_keyword_search(keyword, container):
840
  try:
841
  query = f"SELECT * FROM c WHERE CONTAINS(c.content, '{keyword}')"
 
862
  except Exception as e:
863
  st.error(f"Error saving {doc_id}: {str(e)}")
864
 
865
+ # πŸ€–πŸ€–πŸ€– NEW AI MODALITY RECORD TEMPLATES πŸ€–πŸ€–πŸ€–
 
 
866
  def new_ai_record(container):
867
  new_id = generate_unique_id()
868
  default_doc = {
 
904
  st.error("Error creating links record: " + message)
905
  return None
906
 
907
+ # 🏷️🏷️🏷️ SIDEBAR DATA GRID (Editable Names Grid) 🏷️🏷️🏷️
 
 
908
  def edit_names_grid(container):
909
  records = get_documents(container)
910
  data = []
 
937
  st.sidebar.error(f"Update error for {doc_id}: {message}")
938
  st.rerun()
939
 
940
+ # πŸ”ŽπŸ”ŽπŸ”Ž SEARCH DOCUMENTS UI πŸ”ŽπŸ”ŽπŸ”Ž
 
 
 
941
  def search_documents_ui(container):
942
  with st.sidebar.form("search_form"):
943
  keyword = st.text_input("Search Keyword", key="search_keyword")
 
945
  if submitted and keyword:
946
  display_search_results(keyword, container)
947
 
948
+ # πŸ› οΈπŸ› οΈπŸ› οΈ MAIN FUNCTION πŸ› οΈπŸ› οΈπŸ› οΈ
 
 
949
  def main():
950
  st.markdown("### πŸ™ GitCosmos - Cosmos & Git Hub")
951
  st.markdown(f"[πŸ”— Portal]({CosmosDBUrl})")
 
959
  st.error("Missing Cosmos Key πŸ”‘βŒ")
960
  return
961
 
962
+ # ── CosmosDB Demo Features in Sidebar ──
963
  st.sidebar.markdown("## CosmosDB Demo Features")
964
  demo_feature = st.sidebar.selectbox("Select a Demo",
965
  ["Select", "Create Database", "Create Container", "Create Analytical Container",
 
993
  elif demo_feature == "Item Response Headers":
994
  demo_item_response_headers()
995
 
996
+ # ── Existing Sidebar Items (Item Management, File Management, etc.) ──
997
  st.sidebar.markdown("## πŸ› οΈ Item Management")
998
  if st.sidebar.button("New Item"):
999
  if st.session_state.get("current_container"):
 
1023
  search_documents_ui(st.session_state.get("current_container"))
1024
  show_sidebar_data_grid()
1025
 
1026
+ # Continue with your other UI sections (navigation, file management, document editing, etc.)
1027
  try:
1028
  if st.session_state.get("client") is None:
1029
  st.session_state.client = CosmosClient(ENDPOINT, credential=st.session_state.primary_key)
 
1050
  submitted = st.form_submit_button("Create Container")
1051
  if submitted:
1052
  analytical_ttl = -1 if new_analytical else None
1053
+ # Using create_container method directly (adjust if you have an advanced function)
1054
  new_container = database.create_container(
1055
  id=new_container_id,
1056
  partition_key=PartitionKey(path=new_partition_key),
 
1160
  ai_query = st.text_area("Enter your query for ArXiv search:", key="arxiv_query", height=100)
1161
  if st.button("Send"):
1162
  st.session_state.last_query = ai_query
 
1163
  st.info("Performing AI lookup (function not implemented in this demo)...")
1164
  elif selected_view == 'Clone':
1165
  st.markdown("#### πŸ“„ Clone")