Spaces:
Running
Running
Delete backup.2.app.py
Browse files- backup.2.app.py +0 -78
backup.2.app.py
DELETED
@@ -1,78 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from azure.cosmos import CosmosClient
|
3 |
-
import os
|
4 |
-
|
5 |
-
# Cosmos DB configuration
|
6 |
-
ENDPOINT = "https://acae-afd.documents.azure.com:443/"
|
7 |
-
SUBSCRIPTION_ID = "003fba60-5b3f-48f4-ab36-3ed11bc40816"
|
8 |
-
|
9 |
-
# You'll need to set these environment variables or use Azure Key Vault
|
10 |
-
DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
|
11 |
-
CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
|
12 |
-
Key = os.environ.get("Key")
|
13 |
-
|
14 |
-
def insert_record(record):
|
15 |
-
try:
|
16 |
-
response = container.create_item(body=record)
|
17 |
-
return True, response
|
18 |
-
except Exception as e:
|
19 |
-
return False, str(e)
|
20 |
-
|
21 |
-
# Streamlit app
|
22 |
-
st.title("๐ Cosmos DB Record Insertion")
|
23 |
-
|
24 |
-
# Login section
|
25 |
-
if 'logged_in' not in st.session_state:
|
26 |
-
st.session_state.logged_in = False
|
27 |
-
|
28 |
-
if not st.session_state.logged_in:
|
29 |
-
st.subheader("๐ Login")
|
30 |
-
#input_key = st.text_input("Enter your Cosmos DB Primary Key", type="password")
|
31 |
-
input_key = Key
|
32 |
-
if st.button("๐ Login"):
|
33 |
-
if input_key:
|
34 |
-
st.session_state.primary_key = input_key
|
35 |
-
st.session_state.logged_in = True
|
36 |
-
st.rerun()
|
37 |
-
else:
|
38 |
-
st.error("Please enter a valid key")
|
39 |
-
else:
|
40 |
-
# Initialize Cosmos DB client
|
41 |
-
client = CosmosClient(ENDPOINT, credential=st.session_state.primary_key)
|
42 |
-
database = client.get_database_client(DATABASE_NAME)
|
43 |
-
container = database.get_container_client(CONTAINER_NAME)
|
44 |
-
|
45 |
-
# Input fields
|
46 |
-
st.subheader("๐ Enter Record Details")
|
47 |
-
id = st.text_input("ID")
|
48 |
-
name = st.text_input("Name")
|
49 |
-
age = st.number_input("Age", min_value=0, max_value=150)
|
50 |
-
city = st.text_input("City")
|
51 |
-
|
52 |
-
# Submit button
|
53 |
-
if st.button("๐พ Insert Record"):
|
54 |
-
record = {
|
55 |
-
"id": id,
|
56 |
-
"name": name,
|
57 |
-
"age": age,
|
58 |
-
"city": city
|
59 |
-
}
|
60 |
-
|
61 |
-
success, response = insert_record(record)
|
62 |
-
if success:
|
63 |
-
st.success("โ
Record inserted successfully!")
|
64 |
-
st.json(response)
|
65 |
-
else:
|
66 |
-
st.error(f"โ Failed to insert record: {response}")
|
67 |
-
|
68 |
-
# Logout button
|
69 |
-
if st.button("๐ช Logout"):
|
70 |
-
st.session_state.logged_in = False
|
71 |
-
st.rerun()
|
72 |
-
|
73 |
-
# Display connection info
|
74 |
-
st.sidebar.subheader("๐ Connection Information")
|
75 |
-
st.sidebar.text(f"Endpoint: {ENDPOINT}")
|
76 |
-
st.sidebar.text(f"Subscription ID: {SUBSCRIPTION_ID}")
|
77 |
-
st.sidebar.text(f"Database: {DATABASE_NAME}")
|
78 |
-
st.sidebar.text(f"Container: {CONTAINER_NAME}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|