awacke1 commited on
Commit
f12ce5a
1 Parent(s): 5d21a64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -135,7 +135,38 @@ https://github.com/AaronCWacker/ThreeDragons
135
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/ZemsxlT3b5idB0W5IjL1o.png)
136
  ''')
137
 
 
 
 
138
 
139
- def query_params_demo():
140
- # Accessing a single query parameter
141
- first_key = st.query_params
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/620630b603825909dcbeba35/ZemsxlT3b5idB0W5IjL1o.png)
136
  ''')
137
 
138
+ # Function to handle repeated query parameters
139
+ def get_all_query_params(key):
140
+ return st.experimental_get_query_params().get(key, [])
141
 
142
+ # Function to clear all query parameters
143
+ def clear_query_params():
144
+ st.experimental_set_query_params() # Clear by setting to empty
145
+
146
+
147
+ st.title("Query Parameters Demo")
148
+
149
+ # Display current query parameters
150
+ st.write("Current Query Parameters:", st.experimental_get_query_params())
151
+
152
+ # Example: Using query parameters to navigate or trigger functionalities
153
+ if 'action' in st.experimental_get_query_params():
154
+ action = st.experimental_get_query_params()['action'][0] # Get the first (or only) 'action' parameter
155
+ if action == 'show_message':
156
+ st.success("Showing a message because 'action=show_message' was found in the URL.")
157
+ elif action == 'clear':
158
+ clear_query_params()
159
+ st.experimental_rerun()
160
+
161
+ # Handling repeated keys
162
+ if 'multi' in st.experimental_get_query_params():
163
+ multi_values = get_all_query_params('multi')
164
+ st.write("Values for 'multi':", multi_values)
165
+
166
+ # Manual entry for demonstration
167
+ st.write("Enter query parameters in the URL like this: ?action=show_message&multi=1&multi=2")
168
+
169
+ # Clear query parameters button
170
+ if st.button("Clear Query Parameters"):
171
+ clear_query_params()
172
+ st.experimental_rerun()