Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from azure.cosmos import CosmosClient
|
3 |
+
from azure.storage.blob import BlobServiceClient
|
4 |
+
import requests
|
5 |
+
|
6 |
+
# Azure Services Initialization (Replace with actual credentials)
|
7 |
+
cosmos_client = CosmosClient('<your_cosmos_account_url>', credential='<your_cosmos_key>')
|
8 |
+
blob_service = BlobServiceClient.from_connection_string('<your_blob_storage_connection_string>')
|
9 |
+
|
10 |
+
# Streamlit UI
|
11 |
+
st.title('Azure Services - Streamlit Integration')
|
12 |
+
|
13 |
+
# Azure Cosmos DB - CRUD Operations
|
14 |
+
st.subheader('Azure Cosmos DB - CRUD Operations')
|
15 |
+
cosmos_db = st.text_input('Database Name')
|
16 |
+
cosmos_container = st.text_input('Container Name')
|
17 |
+
item_id = st.text_input("Item ID (for Read, Update, Delete)")
|
18 |
+
item_data = st.text_area("Item Data (JSON format, for Create and Update)")
|
19 |
+
|
20 |
+
if st.button('Create Item in Cosmos DB'):
|
21 |
+
container = cosmos_client.get_container_client(cosmos_db, cosmos_container)
|
22 |
+
container.create_item(item_data)
|
23 |
+
|
24 |
+
if st.button('Read Item from Cosmos DB'):
|
25 |
+
container = cosmos_client.get_container_client(cosmos_db, cosmos_container)
|
26 |
+
item = container.read_item(item_id, partition_key=item_id)
|
27 |
+
st.json(item)
|
28 |
+
|
29 |
+
# Azure Blob Storage - Upload/Download
|
30 |
+
st.subheader('Azure Blob Storage - Upload/Download')
|
31 |
+
blob_container = st.text_input('Blob Container')
|
32 |
+
blob_file = st.file_uploader('Upload file to Blob')
|
33 |
+
|
34 |
+
if blob_file is not None and st.button('Upload to Blob'):
|
35 |
+
blob_client = blob_service.get_blob_client(container=blob_container, blob=blob_file.name)
|
36 |
+
blob_client.upload_blob(blob_file.getvalue())
|
37 |
+
|
38 |
+
# Azure Functions - Trigger
|
39 |
+
st.subheader('Azure Functions - Trigger')
|
40 |
+
function_url = st.text_input('Function URL')
|
41 |
+
if st.button('Call Azure Function'):
|
42 |
+
response = requests.get(function_url)
|
43 |
+
st.write('Function Response:', response.text)
|