awacke1 commited on
Commit
0f38549
β€’
1 Parent(s): 9ae9c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -21
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 a dummy partition key value
89
- partition_key = "dummy_partition_key"
90
  return container.scripts.execute_stored_procedure(
91
  sproc='processQTPrompts',
92
  params=[prompt_text],
93
- partition_key=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
- #input_key = st.text_input("Enter your Cosmos DB Primary Key", type="password")
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
- # Input field for QT prompts
124
- st.subheader("πŸ“ Enter QT Prompts")
125
- 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"
126
- qt_prompts = st.text_area("QT Prompts", value=default_text, height=300)
127
-
128
- # Submit button
129
- if st.button("πŸš€ Process QT Prompts"):
130
- try:
131
- results = process_qt_prompts(container, qt_prompts)
 
 
 
 
 
 
 
 
132
 
133
- # Display results in a dataframe
134
- df_data = [{"Prompt": item['id'], "Occurrence Count": item['occurrenceCount']} for item in results]
135
- st.dataframe(df_data)
136
- except Exception as e:
137
- st.error(f"An error occurred: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  # Logout button
140
  if st.button("πŸšͺ Logout"):
141
  st.session_state.logged_in = False
142
- st.experimental_rerun()
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")