From 3df109adfccedeb134dea4ba2ea9a2da89872048 Mon Sep 17 00:00:00 2001
From: Isuxiz Slidder <48672727+Isuxiz@users.noreply.github.com>
Date: 星期一, 31 三月 2025 17:51:52 +0800
Subject: [PATCH] Update model.py to fix "IndexError: index 1 is out of bounds for dimension 1 with size 0" (#2454)
---
funasr/utils/misc.py | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/funasr/utils/misc.py b/funasr/utils/misc.py
index 4613cb3..eb17f97 100644
--- a/funasr/utils/misc.py
+++ b/funasr/utils/misc.py
@@ -94,3 +94,26 @@
filename, extension = os.path.splitext(filename_with_extension)
# 杩斿洖涓嶅寘鍚墿灞曞悕鐨勬枃浠跺悕
return filename
+
+
+def smart_remove(path):
+ """Intelligently removes files, empty directories, and non-empty directories recursively."""
+ # Check if the provided path exists
+ if not os.path.exists(path):
+ print(f"{path} does not exist.")
+ return
+
+ # If the path is a file, delete it
+ if os.path.isfile(path):
+ os.remove(path)
+ print(f"File {path} has been deleted.")
+ # If the path is a directory
+ elif os.path.isdir(path):
+ try:
+ # Attempt to remove an empty directory
+ os.rmdir(path)
+ print(f"Empty directory {path} has been deleted.")
+ except OSError:
+ # If the directory is not empty, remove it along with all its contents
+ shutil.rmtree(path)
+ print(f"Non-empty directory {path} has been recursively deleted.")
--
Gitblit v1.9.1