From 28ccfbfc51068a663a80764e14074df5edf2b5ba Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期五, 13 三月 2026 17:41:41 +0800
Subject: [PATCH] 提交

---
 funasr/utils/misc.py |   51 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/funasr/utils/misc.py b/funasr/utils/misc.py
index 5eaa4f8..eb17f97 100644
--- a/funasr/utils/misc.py
+++ b/funasr/utils/misc.py
@@ -70,11 +70,50 @@
 
     yaml_file = os.path.join(kwargs.get("output_dir", "./"), "config.yaml")
     OmegaConf.save(config=kwargs, f=yaml_file)
-    print(kwargs)
+    logging.info(f"kwargs: {kwargs}")
     logging.info("config.yaml is saved to: %s", yaml_file)
 
-    # model_path = kwargs.get("model_path")
-    # if model_path is not None:
-    #     config_json = os.path.join(model_path, "configuration.json")
-    #     if os.path.exists(config_json):
-    #         shutil.copy(config_json, os.path.join(kwargs.get("output_dir", "./"), "configuration.json"))
+    model_path = kwargs.get("model_path", None)
+    if model_path is not None:
+        config_json = os.path.join(model_path, "configuration.json")
+        if os.path.exists(config_json):
+            shutil.copy(
+                config_json, os.path.join(kwargs.get("output_dir", "./"), "configuration.json")
+            )
+
+
+def extract_filename_without_extension(file_path):
+    """
+    浠庣粰瀹氱殑鏂囦欢璺緞涓彁鍙栨枃浠跺悕锛堜笉鍖呭惈璺緞鍜屾墿灞曞悕锛�
+    :param file_path: 瀹屾暣鐨勬枃浠惰矾寰�
+    :return: 鏂囦欢鍚嶏紙涓嶅惈璺緞鍜屾墿灞曞悕锛�
+    """
+    # 棣栧厛锛屼娇鐢╫s.path.basename鑾峰彇璺緞涓殑鏂囦欢鍚嶉儴鍒嗭紙鍚墿灞曞悕锛�
+    filename_with_extension = os.path.basename(file_path)
+    # 鐒跺悗锛屼娇鐢╫s.path.splitext鍒嗙鏂囦欢鍚嶅拰鎵╁睍鍚�
+    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