rufimelo commited on
Commit
747b4b8
·
1 Parent(s): be2530a

fix: improve file browser layout - use selectbox instead of cramped columns

Browse files
Files changed (1) hide show
  1. streamlit_app.py +48 -33
streamlit_app.py CHANGED
@@ -498,41 +498,56 @@ with tab4:
498
 
499
  if files:
500
  st.markdown(f"#### Files in {selected_paper_browse}")
501
- for file_path in files:
502
- col1, col2 = st.columns([3, 1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  with col1:
504
- st.write(f"📄 `{file_path.name}`")
505
  with col2:
506
- # Read and display file
507
- try:
508
- if file_path.suffix == ".md":
509
- with open(file_path, "r") as f:
510
- content = f.read()
511
- with st.expander("View", expanded=False):
512
- st.markdown(content)
513
- elif file_path.suffix == ".json":
514
- with open(file_path, "r") as f:
515
- content = json.load(f)
516
- with st.expander("View", expanded=False):
517
- st.json(content)
518
- elif file_path.suffix == ".txt":
519
- with open(file_path, "r") as f:
520
- content = f.read()
521
- with st.expander("View", expanded=False):
522
- st.code(content)
523
- else:
524
- st.write("(binary or unsupported format)")
525
- except Exception as e:
526
- st.write(f"(error: {str(e)})")
527
-
528
- # Download button
529
- with open(file_path, "rb") as f:
530
- st.download_button(
531
- label="⬇️",
532
- data=f.read(),
533
- file_name=file_path.name,
534
- key=f"download_{file_path.name}",
535
- )
536
  else:
537
  st.info(f"No files found in {selected_paper_browse}")
538
  else:
 
498
 
499
  if files:
500
  st.markdown(f"#### Files in {selected_paper_browse}")
501
+
502
+ # Create file selector
503
+ file_names = [f.name for f in files]
504
+ selected_file_name = st.selectbox(
505
+ "Select file to view:",
506
+ file_names,
507
+ key="file_browser_select",
508
+ )
509
+
510
+ # Find the selected file
511
+ selected_file_path = None
512
+ for f in files:
513
+ if f.name == selected_file_name:
514
+ selected_file_path = f
515
+ break
516
+
517
+ if selected_file_path:
518
+ # Show file info and download button
519
+ col1, col2 = st.columns([4, 1])
520
  with col1:
521
+ st.markdown(f"**File:** `{selected_file_path.name}`")
522
  with col2:
523
+ with open(selected_file_path, "rb") as f:
524
+ st.download_button(
525
+ label="📥 Download",
526
+ data=f.read(),
527
+ file_name=selected_file_path.name,
528
+ key=f"download_{selected_file_path.name}",
529
+ )
530
+
531
+ st.markdown("---")
532
+
533
+ # Display file content
534
+ try:
535
+ if selected_file_path.suffix == ".md":
536
+ with open(selected_file_path, "r") as f:
537
+ content = f.read()
538
+ st.markdown(content)
539
+ elif selected_file_path.suffix == ".json":
540
+ with open(selected_file_path, "r") as f:
541
+ content = json.load(f)
542
+ st.json(content)
543
+ elif selected_file_path.suffix == ".txt":
544
+ with open(selected_file_path, "r") as f:
545
+ content = f.read()
546
+ st.code(content)
547
+ else:
548
+ st.info("Binary or unsupported file format")
549
+ except Exception as e:
550
+ st.error(f"Error reading file: {str(e)}")
 
 
551
  else:
552
  st.info(f"No files found in {selected_paper_browse}")
553
  else: