Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
|
|
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
|
|
|
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
|
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
|