Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,54 @@ def display_cosmos_db_structure():
|
|
34 |
# Button to Trigger Display of Cosmos DB Structure
|
35 |
if st.button('Show Cosmos DB Structure'):
|
36 |
display_cosmos_db_structure()
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Streamlit UI
|
39 |
st.title('Azure Services Integration with Streamlit')
|
40 |
|
|
|
34 |
# Button to Trigger Display of Cosmos DB Structure
|
35 |
if st.button('Show Cosmos DB Structure'):
|
36 |
display_cosmos_db_structure()
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
# Function to Add an Item
|
41 |
+
def add_item_to_container(database_name, container_name, item):
|
42 |
+
container = cosmos_client.get_database_client(database_name).get_container_client(container_name)
|
43 |
+
container.create_item(item)
|
44 |
+
|
45 |
+
# Function to Get All Item Keys from a Container
|
46 |
+
def get_all_item_keys(database_name, container_name):
|
47 |
+
container = cosmos_client.get_database_client(database_name).get_container_client(container_name)
|
48 |
+
items = list(container.query_items(
|
49 |
+
query="SELECT c.id FROM c",
|
50 |
+
enable_cross_partition_query=True))
|
51 |
+
return [item['id'] for item in items]
|
52 |
+
|
53 |
+
# Function to Retrieve and Display an Item
|
54 |
+
def display_item(database_name, container_name, item_id):
|
55 |
+
container = cosmos_client.get_database_client(database_name).get_container_client(container_name)
|
56 |
+
item = container.read_item(item_id, partition_key=PartitionKey(item_id))
|
57 |
+
st.markdown(f"- **Item ID**: {item_id}, **Content**: {json.dumps(item)}")
|
58 |
+
|
59 |
+
# Test Function to Add and Retrieve Image Prompts
|
60 |
+
def test_image_prompts(database_name, container_name):
|
61 |
+
# Sample data
|
62 |
+
image_prompts = [{"id": f"image_{i}", "prompt": f"Image prompt {i}", "image_url": f"http://example.com/image_{i}.jpg"} for i in range(10)]
|
63 |
+
|
64 |
+
# Add items
|
65 |
+
for item in image_prompts:
|
66 |
+
add_item_to_container(database_name, container_name, item)
|
67 |
+
|
68 |
+
# Retrieve and display items
|
69 |
+
item_keys = get_all_item_keys(database_name, container_name)
|
70 |
+
for key in item_keys:
|
71 |
+
display_item(database_name, container_name, key)
|
72 |
+
|
73 |
+
# UI to Test Image Prompts Function
|
74 |
+
if st.button('Test Image Prompts'):
|
75 |
+
test_database_name = st.text_input('Enter Test Database Name')
|
76 |
+
test_container_name = st.text_input('Enter Test Container Name')
|
77 |
+
if test_database_name and test_container_name:
|
78 |
+
test_image_prompts(test_database_name, test_container_name)
|
79 |
+
else:
|
80 |
+
st.error('Please enter the test database and container names.')
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
# Streamlit UI
|
86 |
st.title('Azure Services Integration with Streamlit')
|
87 |
|