Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Set Azure connection string and container name
|
6 |
+
connect_str = 'your-azure-connection-string'
|
7 |
+
container_name = 'your-container-name'
|
8 |
+
|
9 |
+
def save_to_azure(file):
|
10 |
+
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
|
11 |
+
blob_client = blob_service_client.get_blob_client(container_name, file.name)
|
12 |
+
|
13 |
+
blob_client.upload_blob(file, overwrite=True)
|
14 |
+
|
15 |
+
def list_blobs():
|
16 |
+
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
|
17 |
+
container_client = blob_service_client.get_container_client(container_name)
|
18 |
+
|
19 |
+
blob_list = container_client.list_blobs()
|
20 |
+
for blob in blob_list:
|
21 |
+
st.write(blob.name)
|
22 |
+
|
23 |
+
def app():
|
24 |
+
st.title('Azure Blob Storage App')
|
25 |
+
|
26 |
+
file = st.file_uploader("Upload a file", type=['csv', 'txt'])
|
27 |
+
if file is not None:
|
28 |
+
save_to_azure(file)
|
29 |
+
|
30 |
+
if st.button('List Files'):
|
31 |
+
list_blobs()
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
app()
|