awacke1 commited on
Commit
b621ea4
β€’
1 Parent(s): 5347d74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -3
app.py CHANGED
@@ -397,11 +397,76 @@ def SaveFileNameClicked():
397
  newFileText = st.session_state.file_content_area
398
  oldFileText = st.session_state.filetext
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  def FileSidebar():
401
- # ----------------------------------------------------- File Sidebar for Jump Gates ------------------------------------------
 
402
  all_files = glob.glob("*.md")
403
  all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
404
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  Files1, Files2 = st.sidebar.columns(2)
406
  with Files1:
407
  if st.button("πŸ—‘ Delete All"):
@@ -516,7 +581,8 @@ titles = [
516
  "🎺πŸͺ˜ Crescent City πŸŒ™ Rhythms & Grooves πŸŽΉπŸ’ƒ",
517
  "🎷🎸 Mardi Gras 🎭 Melodies",
518
  "🎼🎺 Straight Outta Nawlins ⚜️",
519
- "πŸ₯πŸŽ» Jazzy 🎷 Jambalaya πŸ› of New Orleans' 🏰 Musical 🎹 Soul πŸ™Œ",
 
520
  "πŸ₯πŸŽ» The Music Of New Orleans MoE πŸŽ­πŸŽ‰"
521
  ]
522
  selected_title = random.choice(titles)
@@ -1196,7 +1262,7 @@ def get_audio_download_link(file_path):
1196
 
1197
 
1198
 
1199
- # Wav audio files - Transcription History in Wav
1200
  all_files = glob.glob("*.wav")
1201
  all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
1202
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
 
397
  newFileText = st.session_state.file_content_area
398
  oldFileText = st.session_state.filetext
399
 
400
+
401
+ # Function to compare file sizes and delete duplicates
402
+ def compare_and_delete_files(files):
403
+ if not files:
404
+ st.warning("No files to compare.")
405
+ return
406
+
407
+ # Dictionary to store file sizes and their paths
408
+ file_sizes = {}
409
+ for file in files:
410
+ size = os.path.getsize(file)
411
+ if size in file_sizes:
412
+ file_sizes[size].append(file)
413
+ else:
414
+ file_sizes[size] = [file]
415
+
416
+ # Remove all but the latest file for each size group
417
+ for size, paths in file_sizes.items():
418
+ if len(paths) > 1:
419
+ latest_file = max(paths, key=os.path.getmtime)
420
+ for file in paths:
421
+ if file != latest_file:
422
+ os.remove(file)
423
+ st.success(f"Deleted {file} as a duplicate.")
424
+ st.experimental_rerun()
425
+
426
+ # Function to get file size
427
+ def get_file_size(file_path):
428
+ return os.path.getsize(file_path)
429
+
430
  def FileSidebar():
431
+
432
+ # File Sidebar for files 🌐View, πŸ“‚Open, ▢️Run, and πŸ—‘Delete per file
433
  all_files = glob.glob("*.md")
434
  all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
435
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
436
+
437
+ # Compare file sizes for potential duplicates
438
+ file_sizes = [get_file_size(file) for file in all_files]
439
+ previous_size = None
440
+
441
+
442
+ # User interface
443
+ st.sidebar.title("File Operations")
444
+ for file, size in zip(all_files, file_sizes):
445
+ duplicate_flag = "🚩" if size == previous_size else ""
446
+ with st.sidebar.expander(f"File: {file} {duplicate_flag}"):
447
+ st.text(f"Size: {size} bytes")
448
+
449
+ if st.button("View", key=f"view_{file}"):
450
+ try:
451
+ with open(file, "r", encoding='utf-8') as f: # Ensure the file is read with UTF-8 encoding
452
+ file_content = f.read()
453
+ st.code(file_content, language="markdown")
454
+ except UnicodeDecodeError:
455
+ st.error("Failed to decode the file with UTF-8. It might contain non-UTF-8 encoded characters.")
456
+
457
+ if st.button("Delete", key=f"delete3_{file}"):
458
+ os.remove(file)
459
+ st.experimental_rerun()
460
+ previous_size = size # Update previous size for the next iteration
461
+
462
+
463
+ # Button to compare files and delete duplicates
464
+ #if st.button("Compare and Delete Duplicates"):
465
+ # compare_and_delete_files(all_files)
466
+
467
+
468
+
469
+
470
  Files1, Files2 = st.sidebar.columns(2)
471
  with Files1:
472
  if st.button("πŸ—‘ Delete All"):
 
581
  "🎺πŸͺ˜ Crescent City πŸŒ™ Rhythms & Grooves πŸŽΉπŸ’ƒ",
582
  "🎷🎸 Mardi Gras 🎭 Melodies",
583
  "🎼🎺 Straight Outta Nawlins ⚜️",
584
+ "πŸ₯πŸŽ» Jazzy 🎷 Jambalaya πŸ› of New Orleans",
585
+ "🏰 Musical 🎹 Soul πŸ™Œ",
586
  "πŸ₯πŸŽ» The Music Of New Orleans MoE πŸŽ­πŸŽ‰"
587
  ]
588
  selected_title = random.choice(titles)
 
1262
 
1263
 
1264
 
1265
+ # 🎡 Wav Audio files - Transcription History in Wav
1266
  all_files = glob.glob("*.wav")
1267
  all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 10] # exclude files with short names
1268
  all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order