Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -47,15 +47,15 @@ helpURL = 'https://huggingface.co/awacke1'
|
|
47 |
bugURL = 'https://huggingface.co/spaces/awacke1/AzureCosmosDBUI/'
|
48 |
icons = '๐๐๐ซ'
|
49 |
st.set_page_config(
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
)
|
60 |
|
61 |
# Cosmos DB & App URLs
|
@@ -246,6 +246,7 @@ def archive_current_container(database_name, container_name, client):
|
|
246 |
def create_new_container(database, container_id, partition_key_path,
|
247 |
analytical_storage_ttl=None, indexing_policy=None, vector_embedding_policy=None):
|
248 |
try:
|
|
|
249 |
if analytical_storage_ttl is not None:
|
250 |
container = database.create_container(
|
251 |
id=container_id,
|
@@ -261,11 +262,24 @@ def create_new_container(database, container_id, partition_key_path,
|
|
261 |
indexing_policy=indexing_policy,
|
262 |
vector_embedding_policy=vector_embedding_policy
|
263 |
)
|
264 |
-
except exceptions.CosmosResourceExistsError:
|
265 |
-
container = database.get_container_client(container_id)
|
266 |
except exceptions.CosmosHttpResponseError as e:
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
return container
|
270 |
|
271 |
def advanced_insert_item(container, item):
|
@@ -623,7 +637,7 @@ def main():
|
|
623 |
st.session_state.new_container_created = new_container_id
|
624 |
st.rerun()
|
625 |
|
626 |
-
#
|
627 |
containers = get_containers(database)
|
628 |
if "new_container_created" in st.session_state and st.session_state.new_container_created not in containers:
|
629 |
containers.append(st.session_state.new_container_created)
|
@@ -786,7 +800,7 @@ def main():
|
|
786 |
else:
|
787 |
st.info("No docs.")
|
788 |
|
789 |
-
# GitHub Ops section
|
790 |
st.subheader("๐ GitHub Ops")
|
791 |
github_token = os.environ.get("GITHUB")
|
792 |
source_repo = st.text_input("Source Repo URL", value="https://github.com/AaronCWacker/AIExamples-8-24-Streamlit")
|
@@ -796,7 +810,7 @@ def main():
|
|
796 |
if st.button("๐ฅ Clone Repo"):
|
797 |
if github_token and source_repo:
|
798 |
try:
|
799 |
-
local_path = f"./temp_repo_{datetime.now().strftime('%Y%m%
|
800 |
download_github_repo(source_repo, local_path)
|
801 |
zip_filename = f"{new_repo_name}.zip"
|
802 |
create_zip_file(local_path, zip_filename[:-4])
|
|
|
47 |
bugURL = 'https://huggingface.co/spaces/awacke1/AzureCosmosDBUI/'
|
48 |
icons = '๐๐๐ซ'
|
49 |
st.set_page_config(
|
50 |
+
page_title=title,
|
51 |
+
page_icon=icons,
|
52 |
+
layout="wide",
|
53 |
+
initial_sidebar_state="auto",
|
54 |
+
menu_items={
|
55 |
+
'Get Help': helpURL,
|
56 |
+
'Report a bug': bugURL,
|
57 |
+
'About': title
|
58 |
+
}
|
59 |
)
|
60 |
|
61 |
# Cosmos DB & App URLs
|
|
|
246 |
def create_new_container(database, container_id, partition_key_path,
|
247 |
analytical_storage_ttl=None, indexing_policy=None, vector_embedding_policy=None):
|
248 |
try:
|
249 |
+
# Try creating with analytical_storage_ttl if provided.
|
250 |
if analytical_storage_ttl is not None:
|
251 |
container = database.create_container(
|
252 |
id=container_id,
|
|
|
262 |
indexing_policy=indexing_policy,
|
263 |
vector_embedding_policy=vector_embedding_policy
|
264 |
)
|
|
|
|
|
265 |
except exceptions.CosmosHttpResponseError as e:
|
266 |
+
# If the error is due to the analytical_storage_ttl property not being valid, try again without it.
|
267 |
+
if analytical_storage_ttl is not None and "analyticalStorageTtl" in str(e):
|
268 |
+
try:
|
269 |
+
container = database.create_container(
|
270 |
+
id=container_id,
|
271 |
+
partition_key=PartitionKey(path=partition_key_path),
|
272 |
+
indexing_policy=indexing_policy,
|
273 |
+
vector_embedding_policy=vector_embedding_policy
|
274 |
+
)
|
275 |
+
except Exception as e2:
|
276 |
+
st.error(f"Error creating container without analytical_storage_ttl: {str(e2)}")
|
277 |
+
return None
|
278 |
+
elif isinstance(e, exceptions.CosmosResourceExistsError):
|
279 |
+
container = database.get_container_client(container_id)
|
280 |
+
else:
|
281 |
+
st.error(f"Error creating container: {str(e)}")
|
282 |
+
return None
|
283 |
return container
|
284 |
|
285 |
def advanced_insert_item(container, item):
|
|
|
637 |
st.session_state.new_container_created = new_container_id
|
638 |
st.rerun()
|
639 |
|
640 |
+
# Update container list
|
641 |
containers = get_containers(database)
|
642 |
if "new_container_created" in st.session_state and st.session_state.new_container_created not in containers:
|
643 |
containers.append(st.session_state.new_container_created)
|
|
|
800 |
else:
|
801 |
st.info("No docs.")
|
802 |
|
803 |
+
# GitHub Ops section
|
804 |
st.subheader("๐ GitHub Ops")
|
805 |
github_token = os.environ.get("GITHUB")
|
806 |
source_repo = st.text_input("Source Repo URL", value="https://github.com/AaronCWacker/AIExamples-8-24-Streamlit")
|
|
|
810 |
if st.button("๐ฅ Clone Repo"):
|
811 |
if github_token and source_repo:
|
812 |
try:
|
813 |
+
local_path = f"./temp_repo_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
814 |
download_github_repo(source_repo, local_path)
|
815 |
zip_filename = f"{new_repo_name}.zip"
|
816 |
create_zip_file(local_path, zip_filename[:-4])
|