awacke1 commited on
Commit
2f38a4a
·
verified ·
1 Parent(s): 67609ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -213,6 +213,13 @@ def file_management_sidebar():
213
  st.session_state.selected_file = new_filename
214
  st.session_state.view_mode = 'edit'
215
 
 
 
 
 
 
 
 
216
  # Main application logic
217
  def main():
218
  st.title("Markdown Content with AI Lookup and File Management")
@@ -231,33 +238,35 @@ def main():
231
 
232
  # Process 'q' query parameter from the URL
233
  try:
234
- query_params = st.experimental_get_query_params()
235
  query_list = query_params.get('q') or query_params.get('query') or []
236
  if query_list:
237
  search_query = query_list[0]
238
  if len(search_query) > 1:
 
 
239
  st.write(f"### Search query received: {search_query}")
240
- # Perform AI lookup
241
  ai_result = perform_ai_lookup(search_query)
242
- # Extract URLs from AI result
243
  markdown_text = extract_urls(ai_result)
244
  st.markdown("## Extracted URLs")
245
  st.markdown(markdown_text)
246
- # Save the result as markdown file
 
247
  filename = generate_filename("AI_Result", search_query)
248
  with open(filename, 'w', encoding='utf-8') as f:
249
  f.write(markdown_text)
250
  st.write(f"Generated file **{filename}** with AI lookup results.")
251
- # Clear the query parameters
252
- st.experimental_set_query_params()
253
- # Update session state
254
  st.session_state.selected_file = filename
255
  st.session_state.view_mode = 'view'
 
256
  except Exception as e:
257
  st.write(f"An error occurred while processing query parameters: {e}")
258
 
259
  # Handle 'action' and 'query' parameters
260
- params = st.experimental_get_query_params()
261
  if 'action' in params:
262
  action_list = params['action']
263
  if action_list:
@@ -266,14 +275,13 @@ def main():
266
  st.success("Showing a message because 'action=show_message' was found in the URL.")
267
  elif action == 'clear':
268
  # Clear query parameters
269
- st.experimental_set_query_params()
 
270
  if 'query' in params:
271
  query_list = params['query']
272
  if query_list:
273
  query = query_list[0]
274
- # Display content or image based on the query
275
  st.write(f"Displaying content for query: {query}")
276
- # Implement your display logic here
277
 
278
  # File management sidebar
279
  file_management_sidebar()
 
213
  st.session_state.selected_file = new_filename
214
  st.session_state.view_mode = 'edit'
215
 
216
+ def get_all_query_params(key):
217
+ return st.query_params().get(key, [])
218
+
219
+ def clear_query_params():
220
+ st.query_params()
221
+
222
+
223
  # Main application logic
224
  def main():
225
  st.title("Markdown Content with AI Lookup and File Management")
 
238
 
239
  # Process 'q' query parameter from the URL
240
  try:
241
+ query_params = st.query_params
242
  query_list = query_params.get('q') or query_params.get('query') or []
243
  if query_list:
244
  search_query = query_list[0]
245
  if len(search_query) > 1:
246
+
247
+
248
  st.write(f"### Search query received: {search_query}")
 
249
  ai_result = perform_ai_lookup(search_query)
 
250
  markdown_text = extract_urls(ai_result)
251
  st.markdown("## Extracted URLs")
252
  st.markdown(markdown_text)
253
+
254
+
255
  filename = generate_filename("AI_Result", search_query)
256
  with open(filename, 'w', encoding='utf-8') as f:
257
  f.write(markdown_text)
258
  st.write(f"Generated file **{filename}** with AI lookup results.")
259
+
260
+
261
+ st.query_params.clear()
262
  st.session_state.selected_file = filename
263
  st.session_state.view_mode = 'view'
264
+
265
  except Exception as e:
266
  st.write(f"An error occurred while processing query parameters: {e}")
267
 
268
  # Handle 'action' and 'query' parameters
269
+ params = st.query_params
270
  if 'action' in params:
271
  action_list = params['action']
272
  if action_list:
 
275
  st.success("Showing a message because 'action=show_message' was found in the URL.")
276
  elif action == 'clear':
277
  # Clear query parameters
278
+ st.query_params.clear()
279
+
280
  if 'query' in params:
281
  query_list = params['query']
282
  if query_list:
283
  query = query_list[0]
 
284
  st.write(f"Displaying content for query: {query}")
 
285
 
286
  # File management sidebar
287
  file_management_sidebar()