awacke1 commited on
Commit
28aba27
·
verified ·
1 Parent(s): 10cda6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -23
app.py CHANGED
@@ -232,8 +232,8 @@ def main():
232
 
233
  # Process 'q' query parameter from the URL
234
  try:
235
- query_params = st.query_params
236
- query_list = (query_params.get('q') or query_params.get('query') or [''])
237
  if query_list:
238
  search_query = query_list[0]
239
  if len(search_query) > 1:
@@ -249,14 +249,17 @@ def main():
249
  with open(filename, 'w', encoding='utf-8') as f:
250
  f.write(markdown_text)
251
  st.write(f"Generated file **{filename}** with AI lookup results.")
 
 
252
  # Update file management sidebar
253
  st.experimental_rerun()
254
  except Exception as e:
255
  st.write(f"An error occurred while processing query parameters: {e}")
256
 
257
  # Handle 'action' and 'query' parameters
258
- if 'action' in st.query_params:
259
- action_list = st.query_params['action']
 
260
  if action_list:
261
  action = action_list[0]
262
  if action == 'show_message':
@@ -265,8 +268,8 @@ def main():
265
  # Clear query parameters
266
  st.experimental_set_query_params()
267
  st.experimental_rerun()
268
- if 'query' in st.query_params:
269
- query_list = st.query_params['query']
270
  if query_list:
271
  query = query_list[0]
272
  # Display content or image based on the query
@@ -277,24 +280,29 @@ def main():
277
  file_management_sidebar()
278
 
279
  # Display the selected file
280
- if 'selected_file' in st.session_state:
281
- selected_file = st.session_state.selected_file
282
  view_mode = st.session_state.get('view_mode', 'view')
283
- if view_mode == 'view':
284
- st.markdown(f"### Viewing {selected_file}")
285
- with open(selected_file, 'r', encoding='utf-8') as f:
286
- file_content = f.read()
287
- st.markdown(file_content)
288
- elif view_mode == 'edit':
289
- st.markdown(f"### Editing {selected_file}")
290
- with open(selected_file, 'r', encoding='utf-8') as f:
291
- file_content = f.read()
292
- edited_content = st.text_area("Edit the markdown content", file_content, height=400)
293
- if st.button("Save Changes"):
294
- with open(selected_file, 'w', encoding='utf-8') as f:
295
- f.write(edited_content)
296
- st.success(f"Changes saved to {selected_file}")
297
- st.experimental_rerun()
 
 
 
 
 
298
 
299
  if __name__ == "__main__":
300
  main()
 
232
 
233
  # Process 'q' query parameter from the URL
234
  try:
235
+ query_params = st.experimental_get_query_params()
236
+ query_list = query_params.get('q') or query_params.get('query') or []
237
  if query_list:
238
  search_query = query_list[0]
239
  if len(search_query) > 1:
 
249
  with open(filename, 'w', encoding='utf-8') as f:
250
  f.write(markdown_text)
251
  st.write(f"Generated file **{filename}** with AI lookup results.")
252
+ # Clear the query parameters
253
+ st.experimental_set_query_params()
254
  # Update file management sidebar
255
  st.experimental_rerun()
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:
264
  action = action_list[0]
265
  if action == 'show_message':
 
268
  # Clear query parameters
269
  st.experimental_set_query_params()
270
  st.experimental_rerun()
271
+ if 'query' in params:
272
+ query_list = params['query']
273
  if query_list:
274
  query = query_list[0]
275
  # Display content or image based on the query
 
280
  file_management_sidebar()
281
 
282
  # Display the selected file
283
+ selected_file = st.session_state.get('selected_file')
284
+ if selected_file:
285
  view_mode = st.session_state.get('view_mode', 'view')
286
+ if os.path.exists(selected_file):
287
+ if view_mode == 'view':
288
+ st.markdown(f"### Viewing {selected_file}")
289
+ with open(selected_file, 'r', encoding='utf-8') as f:
290
+ file_content = f.read()
291
+ st.markdown(file_content)
292
+ elif view_mode == 'edit':
293
+ st.markdown(f"### Editing {selected_file}")
294
+ with open(selected_file, 'r', encoding='utf-8') as f:
295
+ file_content = f.read()
296
+ edited_content = st.text_area("Edit the markdown content", file_content, height=400)
297
+ if st.button("Save Changes"):
298
+ with open(selected_file, 'w', encoding='utf-8') as f:
299
+ f.write(edited_content)
300
+ st.success(f"Changes saved to {selected_file}")
301
+ st.experimental_rerun()
302
+ else:
303
+ st.error("Selected file does not exist.")
304
+ else:
305
+ st.info("No file selected.")
306
 
307
  if __name__ == "__main__":
308
  main()