Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from azure.cosmos import CosmosClient, PartitionKey
|
3 |
import os
|
4 |
-
import re
|
5 |
|
6 |
# Cosmos DB configuration
|
7 |
ENDPOINT = "https://acae-afd.documents.azure.com:443/"
|
@@ -10,7 +9,6 @@ SUBSCRIPTION_ID = "003fba60-5b3f-48f4-ab36-3ed11bc40816"
|
|
10 |
# You'll need to set these environment variables or use Azure Key Vault
|
11 |
DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
|
12 |
CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
|
13 |
-
Key = os.environ.get("Key")
|
14 |
|
15 |
def create_stored_procedure(container):
|
16 |
stored_procedure_definition = {
|
@@ -28,8 +26,8 @@ def create_stored_procedure(container):
|
|
28 |
var prompt = prompts[i].trim();
|
29 |
if (prompt.startsWith('QT ')) {
|
30 |
var querySpec = {
|
31 |
-
query: "SELECT * FROM c WHERE c.
|
32 |
-
parameters: [{ name: "@
|
33 |
};
|
34 |
|
35 |
var isAccepted = container.queryDocuments(
|
@@ -53,7 +51,7 @@ def create_stored_procedure(container):
|
|
53 |
} else {
|
54 |
// Create new record
|
55 |
var newItem = {
|
56 |
-
|
57 |
occurrenceCount: 1,
|
58 |
evaluation: ""
|
59 |
};
|
@@ -86,10 +84,12 @@ def ensure_stored_procedure_exists(container):
|
|
86 |
create_stored_procedure(container)
|
87 |
|
88 |
def process_qt_prompts(container, prompt_text):
|
|
|
|
|
89 |
return container.scripts.execute_stored_procedure(
|
90 |
sproc='processQTPrompts',
|
91 |
params=[prompt_text],
|
92 |
-
partition_key=
|
93 |
)
|
94 |
|
95 |
# Streamlit app
|
@@ -101,13 +101,12 @@ if 'logged_in' not in st.session_state:
|
|
101 |
|
102 |
if not st.session_state.logged_in:
|
103 |
st.subheader("๐ Login")
|
104 |
-
|
105 |
-
input_key = Key
|
106 |
if st.button("๐ Login"):
|
107 |
if input_key:
|
108 |
st.session_state.primary_key = input_key
|
109 |
st.session_state.logged_in = True
|
110 |
-
st.
|
111 |
else:
|
112 |
st.error("Please enter a valid key")
|
113 |
else:
|
@@ -126,11 +125,14 @@ else:
|
|
126 |
|
127 |
# Submit button
|
128 |
if st.button("๐ Process QT Prompts"):
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
134 |
|
135 |
# Logout button
|
136 |
if st.button("๐ช Logout"):
|
|
|
1 |
import streamlit as st
|
2 |
from azure.cosmos import CosmosClient, PartitionKey
|
3 |
import os
|
|
|
4 |
|
5 |
# Cosmos DB configuration
|
6 |
ENDPOINT = "https://acae-afd.documents.azure.com:443/"
|
|
|
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 |
|
13 |
def create_stored_procedure(container):
|
14 |
stored_procedure_definition = {
|
|
|
26 |
var prompt = prompts[i].trim();
|
27 |
if (prompt.startsWith('QT ')) {
|
28 |
var querySpec = {
|
29 |
+
query: "SELECT * FROM c WHERE c.id = @id",
|
30 |
+
parameters: [{ name: "@id", value: prompt }]
|
31 |
};
|
32 |
|
33 |
var isAccepted = container.queryDocuments(
|
|
|
51 |
} else {
|
52 |
// Create new record
|
53 |
var newItem = {
|
54 |
+
id: prompt,
|
55 |
occurrenceCount: 1,
|
56 |
evaluation: ""
|
57 |
};
|
|
|
84 |
create_stored_procedure(container)
|
85 |
|
86 |
def process_qt_prompts(container, prompt_text):
|
87 |
+
# Use a dummy partition key value
|
88 |
+
partition_key = "dummy_partition_key"
|
89 |
return container.scripts.execute_stored_procedure(
|
90 |
sproc='processQTPrompts',
|
91 |
params=[prompt_text],
|
92 |
+
partition_key=partition_key
|
93 |
)
|
94 |
|
95 |
# Streamlit app
|
|
|
101 |
|
102 |
if not st.session_state.logged_in:
|
103 |
st.subheader("๐ Login")
|
104 |
+
input_key = st.text_input("Enter your Cosmos DB Primary Key", type="password")
|
|
|
105 |
if st.button("๐ Login"):
|
106 |
if input_key:
|
107 |
st.session_state.primary_key = input_key
|
108 |
st.session_state.logged_in = True
|
109 |
+
st.experimental_rerun()
|
110 |
else:
|
111 |
st.error("Please enter a valid key")
|
112 |
else:
|
|
|
125 |
|
126 |
# Submit button
|
127 |
if st.button("๐ Process QT Prompts"):
|
128 |
+
try:
|
129 |
+
results = process_qt_prompts(container, qt_prompts)
|
130 |
+
|
131 |
+
# Display results in a dataframe
|
132 |
+
df_data = [{"Prompt": item['id'], "Occurrence Count": item['occurrenceCount']} for item in results]
|
133 |
+
st.dataframe(df_data)
|
134 |
+
except Exception as e:
|
135 |
+
st.error(f"An error occurred: {str(e)}")
|
136 |
|
137 |
# Logout button
|
138 |
if st.button("๐ช Logout"):
|