awacke1 commited on
Commit
f225c7e
Β·
verified Β·
1 Parent(s): 367ef97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -24
app.py CHANGED
@@ -430,48 +430,67 @@ def FileSidebar():
430
  for file in all_files:
431
  ext = os.path.splitext(file)[1].lower()
432
  col1, col2, col3, col4, col5 = st.sidebar.columns([1, 6, 1, 1, 1])
 
 
433
  with col1: # View
434
  icon = "πŸ“œ" if ext == ".md" else "πŸ“„" if ext == ".pdf" else "πŸ–ΌοΈ" if ext in [".png", ".jpg", ".jpeg"] else "🎡" if ext in [".wav", ".mp3"] else "πŸŽ₯" if ext == ".mp4" else "πŸ“Ž"
435
  if st.button(icon, key=f"view_{file}"):
 
436
  with open(file, "rb") as f:
437
  content = f.read()
438
- if ext == ".md":
439
- st.markdown(content.decode("utf-8"))
440
- SpeechSynthesis(content.decode("utf-8"))
441
- elif ext == ".pdf":
442
- st.download_button("Download PDF", content, file, "application/pdf")
443
- st.write("PDF Viewer not natively supported; download to view.")
444
- elif ext in [".png", ".jpg", ".jpeg"]:
445
- st.image(content, use_column_width=True)
446
- elif ext in [".wav", ".mp3"]:
447
- st.audio(content, format=f"audio/{ext[1:]}")
448
- elif ext == ".mp4":
449
- st.video(content, format="video/mp4")
450
  with col2: # Download link
451
  st.markdown(get_table_download_link(file), unsafe_allow_html=True)
 
452
  with col3: # Open
453
  if st.button("πŸ“‚", key=f"open_{file}"):
 
454
  with open(file, "rb") as f:
455
  content = f.read()
456
- if ext == ".md":
457
- st.text_area(f"Editing {file}", value=content.decode("utf-8"), height=300, key=f"edit_{file}")
458
- elif ext == ".pdf":
459
- st.download_button("Download PDF to Edit", content, file, "application/pdf")
460
- st.write("PDF editing not supported in-app; download to edit externally.")
461
- elif ext in [".png", ".jpg", ".jpeg"]:
462
- st.image(content, use_column_width=True, caption=f"Viewing {file}")
463
- elif ext in [".wav", ".mp3"]:
464
- st.audio(content, format=f"audio/{ext[1:]}")
465
- elif ext == ".mp4":
466
- st.video(content, format="video/mp4")
467
  with col4: # Run
468
  if st.button("▢️", key=f"run_{file}"):
469
  if ext == ".md":
470
- process_text(open(file, "r", encoding="utf-8").read())
 
 
 
471
  with col5: # Delete
472
  if st.button("πŸ—‘", key=f"delete_{file}"):
473
  os.remove(file)
474
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
476
  def create_zip_of_files(files):
477
  zip_name = "Files.zip"
 
430
  for file in all_files:
431
  ext = os.path.splitext(file)[1].lower()
432
  col1, col2, col3, col4, col5 = st.sidebar.columns([1, 6, 1, 1, 1])
433
+ colFollowUp = "" # Flag to trigger main-area display
434
+
435
  with col1: # View
436
  icon = "πŸ“œ" if ext == ".md" else "πŸ“„" if ext == ".pdf" else "πŸ–ΌοΈ" if ext in [".png", ".jpg", ".jpeg"] else "🎡" if ext in [".wav", ".mp3"] else "πŸŽ₯" if ext == ".mp4" else "πŸ“Ž"
437
  if st.button(icon, key=f"view_{file}"):
438
+ colFollowUp = "view_" + ext
439
  with open(file, "rb") as f:
440
  content = f.read()
441
+
 
 
 
 
 
 
 
 
 
 
 
442
  with col2: # Download link
443
  st.markdown(get_table_download_link(file), unsafe_allow_html=True)
444
+
445
  with col3: # Open
446
  if st.button("πŸ“‚", key=f"open_{file}"):
447
+ colFollowUp = "open_" + ext
448
  with open(file, "rb") as f:
449
  content = f.read()
450
+
 
 
 
 
 
 
 
 
 
 
451
  with col4: # Run
452
  if st.button("▢️", key=f"run_{file}"):
453
  if ext == ".md":
454
+ colFollowUp = "run_" + ext
455
+ with open(file, "rb") as f:
456
+ content = f.read()
457
+
458
  with col5: # Delete
459
  if st.button("πŸ—‘", key=f"delete_{file}"):
460
  os.remove(file)
461
  st.rerun()
462
+
463
+ # Display in main area based on colFollowUp
464
+ if colFollowUp.startswith("view_"):
465
+ if ext == ".md":
466
+ st.markdown(content.decode("utf-8"))
467
+ SpeechSynthesis(content.decode("utf-8"))
468
+ elif ext == ".pdf":
469
+ st.download_button("Download PDF", content, file, "application/pdf")
470
+ st.write("PDF Viewer not natively supported; download to view.")
471
+ elif ext in [".png", ".jpg", ".jpeg"]:
472
+ st.image(content, use_column_width=True)
473
+ elif ext in [".wav", ".mp3"]:
474
+ st.audio(content, format=f"audio/{ext[1:]}")
475
+ elif ext == ".mp4":
476
+ st.video(content, format="video/mp4")
477
+
478
+ elif colFollowUp.startswith("open_"):
479
+ if ext == ".md":
480
+ st.text_area(f"Editing {file}", value=content.decode("utf-8"), height=300, key=f"edit_{file}")
481
+ elif ext == ".pdf":
482
+ st.download_button("Download PDF to Edit", content, file, "application/pdf")
483
+ st.write("PDF editing not supported in-app; download to edit externally.")
484
+ elif ext in [".png", ".jpg", ".jpeg"]:
485
+ st.image(content, use_column_width=True, caption=f"Viewing {file}")
486
+ elif ext in [".wav", ".mp3"]:
487
+ st.audio(content, format=f"audio/{ext[1:]}")
488
+ elif ext == ".mp4":
489
+ st.video(content, format="video/mp4")
490
+
491
+ elif colFollowUp.startswith("run_"):
492
+ if ext == ".md":
493
+ process_text(content.decode("utf-8"))
494
 
495
  def create_zip_of_files(files):
496
  zip_name = "Files.zip"