Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
-
from azure.cosmos import CosmosClient
|
4 |
from azure.cosmos.exceptions import CosmosResourceNotFoundError
|
5 |
import glob
|
6 |
from datetime import datetime
|
@@ -10,11 +10,12 @@ COSMOS_CONNECTION_STRING = os.getenv('COSMOS_CONNECTION_STRING')
|
|
10 |
cosmos_client = CosmosClient.from_connection_string(COSMOS_CONNECTION_STRING)
|
11 |
|
12 |
# Function to Delete Item by ID in Cosmos DB
|
13 |
-
def delete_item_by_id(db_name, container_name, item_id
|
14 |
database_client = cosmos_client.get_database_client(db_name)
|
15 |
container_client = database_client.get_container_client(container_name)
|
16 |
try:
|
17 |
-
|
|
|
18 |
st.success(f"Deleted Item: {item_id}")
|
19 |
except CosmosResourceNotFoundError:
|
20 |
st.error(f"Item not found: {item_id}")
|
@@ -29,11 +30,9 @@ def display_and_manage_cosmos_db():
|
|
29 |
container_name = container_properties['id']
|
30 |
container_client = database_client.get_container_client(container_name)
|
31 |
for item in container_client.read_all_items():
|
32 |
-
|
33 |
-
partition_key_value = item.get('partitionKey', item['id'])
|
34 |
-
st.markdown(f"- **Item ID**: `{item['id']}` - **Partition Key**: `{partition_key_value}`")
|
35 |
if st.button(f"🗑️ Delete {item['id']}", key=f"delete_{item['id']}"):
|
36 |
-
delete_item_by_id(db_name, container_name, item['id']
|
37 |
|
38 |
# Insert PNG Images with Unique Identifiers
|
39 |
def insert_png_images_with_unique_ids():
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
+
from azure.cosmos import CosmosClient, PartitionKey
|
4 |
from azure.cosmos.exceptions import CosmosResourceNotFoundError
|
5 |
import glob
|
6 |
from datetime import datetime
|
|
|
10 |
cosmos_client = CosmosClient.from_connection_string(COSMOS_CONNECTION_STRING)
|
11 |
|
12 |
# Function to Delete Item by ID in Cosmos DB
|
13 |
+
def delete_item_by_id(db_name, container_name, item_id):
|
14 |
database_client = cosmos_client.get_database_client(db_name)
|
15 |
container_client = database_client.get_container_client(container_name)
|
16 |
try:
|
17 |
+
# Using the item ID as the partition key value
|
18 |
+
container_client.delete_item(item=item_id, partition_key=item_id)
|
19 |
st.success(f"Deleted Item: {item_id}")
|
20 |
except CosmosResourceNotFoundError:
|
21 |
st.error(f"Item not found: {item_id}")
|
|
|
30 |
container_name = container_properties['id']
|
31 |
container_client = database_client.get_container_client(container_name)
|
32 |
for item in container_client.read_all_items():
|
33 |
+
st.markdown(f"- **Item ID**: `{item['id']}`")
|
|
|
|
|
34 |
if st.button(f"🗑️ Delete {item['id']}", key=f"delete_{item['id']}"):
|
35 |
+
delete_item_by_id(db_name, container_name, item['id'])
|
36 |
|
37 |
# Insert PNG Images with Unique Identifiers
|
38 |
def insert_png_images_with_unique_ids():
|