Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,16 +85,23 @@ def ensure_stored_procedure_exists(container):
|
|
| 85 |
create_stored_procedure(container)
|
| 86 |
|
| 87 |
def process_qt_prompts(container, prompt_text):
|
| 88 |
-
# Use
|
| 89 |
-
|
| 90 |
return container.scripts.execute_stored_procedure(
|
| 91 |
sproc='processQTPrompts',
|
| 92 |
params=[prompt_text],
|
| 93 |
-
partition_key=
|
| 94 |
)
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Streamlit app
|
| 97 |
-
st.title("π QT Prompt Processor")
|
| 98 |
|
| 99 |
# Login section
|
| 100 |
if 'logged_in' not in st.session_state:
|
|
@@ -102,8 +109,7 @@ if 'logged_in' not in st.session_state:
|
|
| 102 |
|
| 103 |
if not st.session_state.logged_in:
|
| 104 |
st.subheader("π Login")
|
| 105 |
-
|
| 106 |
-
input_key = Key
|
| 107 |
if st.button("π Login"):
|
| 108 |
if input_key:
|
| 109 |
st.session_state.primary_key = input_key
|
|
@@ -120,26 +126,50 @@ else:
|
|
| 120 |
# Ensure the stored procedure exists
|
| 121 |
ensure_stored_procedure_exists(container)
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
st.
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
# Logout button
|
| 140 |
if st.button("πͺ Logout"):
|
| 141 |
st.session_state.logged_in = False
|
| 142 |
-
st.
|
| 143 |
|
| 144 |
# Display connection info
|
| 145 |
st.sidebar.subheader("π Connection Information")
|
|
|
|
| 85 |
create_stored_procedure(container)
|
| 86 |
|
| 87 |
def process_qt_prompts(container, prompt_text):
|
| 88 |
+
# Use the first prompt as the partition key
|
| 89 |
+
first_prompt = prompt_text.split('\n')[0].strip()
|
| 90 |
return container.scripts.execute_stored_procedure(
|
| 91 |
sproc='processQTPrompts',
|
| 92 |
params=[prompt_text],
|
| 93 |
+
partition_key=first_prompt
|
| 94 |
)
|
| 95 |
|
| 96 |
+
def insert_record(container, record):
|
| 97 |
+
try:
|
| 98 |
+
response = container.create_item(body=record)
|
| 99 |
+
return True, response
|
| 100 |
+
except Exception as e:
|
| 101 |
+
return False, str(e)
|
| 102 |
+
|
| 103 |
# Streamlit app
|
| 104 |
+
st.title("π Cosmos DB Record Insertion and QT Prompt Processor")
|
| 105 |
|
| 106 |
# Login section
|
| 107 |
if 'logged_in' not in st.session_state:
|
|
|
|
| 109 |
|
| 110 |
if not st.session_state.logged_in:
|
| 111 |
st.subheader("π Login")
|
| 112 |
+
input_key = st.text_input("Enter your Cosmos DB Primary Key", type="password")
|
|
|
|
| 113 |
if st.button("π Login"):
|
| 114 |
if input_key:
|
| 115 |
st.session_state.primary_key = input_key
|
|
|
|
| 126 |
# Ensure the stored procedure exists
|
| 127 |
ensure_stored_procedure_exists(container)
|
| 128 |
|
| 129 |
+
# Tab for different operations
|
| 130 |
+
tab1, tab2 = st.tabs(["Insert Record", "Process QT Prompts"])
|
| 131 |
+
|
| 132 |
+
with tab1:
|
| 133 |
+
st.subheader("π Enter Record Details")
|
| 134 |
+
id = st.text_input("ID")
|
| 135 |
+
name = st.text_input("Name")
|
| 136 |
+
age = st.number_input("Age", min_value=0, max_value=150)
|
| 137 |
+
city = st.text_input("City")
|
| 138 |
+
|
| 139 |
+
if st.button("πΎ Insert Record"):
|
| 140 |
+
record = {
|
| 141 |
+
"id": id,
|
| 142 |
+
"name": name,
|
| 143 |
+
"age": age,
|
| 144 |
+
"city": city
|
| 145 |
+
}
|
| 146 |
|
| 147 |
+
success, response = insert_record(container, record)
|
| 148 |
+
if success:
|
| 149 |
+
st.success("β
Record inserted successfully!")
|
| 150 |
+
st.json(response)
|
| 151 |
+
else:
|
| 152 |
+
st.error(f"β Failed to insert record: {response}")
|
| 153 |
+
|
| 154 |
+
with tab2:
|
| 155 |
+
st.subheader("π Enter QT Prompts")
|
| 156 |
+
default_text = "QT Crystal finders: Bioluminescent crystal caverns, quantum-powered explorers, prismatic hues, alien planet\nQT robot art: Cybernetic metropolis, sentient androids, rogue AI, neon-infused palette\nQT the Lava girl: Volcanic exoplanet, liquid metal rivers, heat-immune heroine, molten metallic palette"
|
| 157 |
+
qt_prompts = st.text_area("QT Prompts", value=default_text, height=300)
|
| 158 |
+
|
| 159 |
+
if st.button("π Process QT Prompts"):
|
| 160 |
+
try:
|
| 161 |
+
results = process_qt_prompts(container, qt_prompts)
|
| 162 |
+
|
| 163 |
+
# Display results in a dataframe
|
| 164 |
+
df_data = [{"Prompt": item['id'], "Occurrence Count": item['occurrenceCount']} for item in results]
|
| 165 |
+
st.dataframe(df_data)
|
| 166 |
+
except Exception as e:
|
| 167 |
+
st.error(f"An error occurred: {str(e)}")
|
| 168 |
|
| 169 |
# Logout button
|
| 170 |
if st.button("πͺ Logout"):
|
| 171 |
st.session_state.logged_in = False
|
| 172 |
+
st.rerun()
|
| 173 |
|
| 174 |
# Display connection info
|
| 175 |
st.sidebar.subheader("π Connection Information")
|