awacke1 commited on
Commit
f05b0a0
·
1 Parent(s): bfb374f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -15,6 +15,7 @@ cosmos_client = CosmosClient.from_connection_string(COSMOS_CONNECTION_STRING)
15
  # Initialize Azure Blob Storage Client
16
  blob_service = BlobServiceClient.from_connection_string(BLOB_STORAGE_CONNECTION_STRING)
17
 
 
18
  # Function to Retrieve and Display Cosmos DB Structure
19
  def display_cosmos_db_structure():
20
  st.subheader('Azure Cosmos DB Structure')
@@ -30,11 +31,14 @@ def display_cosmos_db_structure():
30
 
31
  items = list(container_client.read_all_items())
32
  for item in items:
33
- st.markdown(f" - Item: `{item['id']}`") # Replace 'id' with the appropriate key if different
 
 
 
 
 
34
 
35
- # Button to Trigger Display of Cosmos DB Structure
36
- if st.button('Show Cosmos DB Structure'):
37
- display_cosmos_db_structure()
38
 
39
  # Function to Add or Update an Item
40
  def add_or_update_item(database_client, container_name, item_id, item_data):
@@ -46,6 +50,20 @@ def add_or_update_item(database_client, container_name, item_id, item_data):
46
  except:
47
  container.create_item(item_data)
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  # Test Function to Insert PNG Images
50
  def test_insert_png_images():
51
  # Get the first database and container
 
15
  # Initialize Azure Blob Storage Client
16
  blob_service = BlobServiceClient.from_connection_string(BLOB_STORAGE_CONNECTION_STRING)
17
 
18
+
19
  # Function to Retrieve and Display Cosmos DB Structure
20
  def display_cosmos_db_structure():
21
  st.subheader('Azure Cosmos DB Structure')
 
31
 
32
  items = list(container_client.read_all_items())
33
  for item in items:
34
+ item_desc = f" - Item: `{item['id']}`"
35
+ if 'file_name' in item and item['file_name'].endswith('.png'):
36
+ st.markdown(item_desc)
37
+ st.image(item['file_name'])
38
+ else:
39
+ st.markdown(item_desc)
40
 
41
+
 
 
42
 
43
  # Function to Add or Update an Item
44
  def add_or_update_item(database_client, container_name, item_id, item_data):
 
50
  except:
51
  container.create_item(item_data)
52
 
53
+ # Function to Add or Update an Item
54
+ def add_or_update_item(database_name, container_name, item_id, item_data):
55
+ container = cosmos_client.get_database_client(database_name).get_container_client(container_name)
56
+ try:
57
+ existing_item = container.read_item(item_id, partition_key=PartitionKey(item_id))
58
+ existing_item.update(item_data)
59
+ container.replace_item(item_id, existing_item)
60
+ except exceptions.CosmosResourceNotFoundError:
61
+ container.create_item(item_data)
62
+
63
+ # Button to Trigger Display of Cosmos DB Structure
64
+ if st.button('Show Cosmos DB Structure'):
65
+ display_cosmos_db_structure()
66
+
67
  # Test Function to Insert PNG Images
68
  def test_insert_png_images():
69
  # Get the first database and container