diff --git a/runtime/python/libtorch/funasr_torch/paraformer_bin.py b/runtime/python/libtorch/funasr_torch/paraformer_bin.py index 16c040678..8e404126a 100644 --- a/runtime/python/libtorch/funasr_torch/paraformer_bin.py +++ b/runtime/python/libtorch/funasr_torch/paraformer_bin.py @@ -37,14 +37,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.torchscript") if quantize: @@ -53,8 +57,10 @@ def __init__( print(".torchscripts does not exist, begin to export torchscript") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="torchscript", quantize=quantize, **kwargs) @@ -258,14 +264,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e if quantize: model_bb_file = os.path.join(model_dir, "model_bb_quant.torchscript") @@ -278,8 +288,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="torchscript", quantize=quantize, **kwargs) diff --git a/runtime/python/libtorch/funasr_torch/sensevoice_bin.py b/runtime/python/libtorch/funasr_torch/sensevoice_bin.py index 608da41cd..c27bfdd83 100644 --- a/runtime/python/libtorch/funasr_torch/sensevoice_bin.py +++ b/runtime/python/libtorch/funasr_torch/sensevoice_bin.py @@ -43,14 +43,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.torchscript") if quantize: @@ -59,8 +63,10 @@ def __init__( print(".torchscripts does not exist, begin to export torchscript") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="torchscript", quantize=quantize, **kwargs) diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py index bde7f442e..94538033c 100644 --- a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py @@ -49,14 +49,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.onnx") if quantize: @@ -65,8 +69,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) @@ -284,14 +290,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e if quantize: model_bb_file = os.path.join(model_dir, "model_quant.onnx") @@ -304,8 +314,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py index 3f63ea020..81b991d4b 100644 --- a/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py @@ -39,14 +39,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e encoder_model_file = os.path.join(model_dir, "model.onnx") decoder_model_file = os.path.join(model_dir, "decoder.onnx") @@ -57,8 +61,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) diff --git a/runtime/python/onnxruntime/funasr_onnx/punc_bin.py b/runtime/python/onnxruntime/funasr_onnx/punc_bin.py index ba55186d0..7fa62d44d 100644 --- a/runtime/python/onnxruntime/funasr_onnx/punc_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/punc_bin.py @@ -39,14 +39,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.onnx") if quantize: @@ -55,8 +59,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py index 8f8ae57df..0bc265ebb 100644 --- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py @@ -46,14 +46,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.onnx") if quantize: @@ -62,8 +66,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) diff --git a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py b/runtime/python/onnxruntime/funasr_onnx/vad_bin.py index f784f2637..1c98b7f92 100644 --- a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/vad_bin.py @@ -39,14 +39,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.onnx") if quantize: @@ -55,8 +59,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs) @@ -224,14 +230,18 @@ def __init__( if not Path(model_dir).exists(): try: from modelscope.hub.snapshot_download import snapshot_download - except: - raise "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting model from modelscope, please install modelscope and try it again. To install modelscope, you could:\n" "\npip3 install -U modelscope\n" "For the users in China, you could install with the command:\n" "\npip3 install -U modelscope -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e try: model_dir = snapshot_download(model_dir, cache_dir=cache_dir) - except: - raise "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( - model_dir - ) + except Exception as e: + raise RuntimeError( + "model_dir must be model_name in modelscope or local path downloaded from modelscope, but is {}".format( + model_dir + ) + ) from e model_file = os.path.join(model_dir, "model.onnx") if quantize: @@ -240,8 +250,10 @@ def __init__( print(".onnx does not exist, begin to export onnx") try: from funasr import AutoModel - except: - raise "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + except ImportError as e: + raise ImportError( + "You are exporting onnx, please install funasr and try it again. To install funasr, you could:\n" "\npip3 install -U funasr\n" "For the users in China, you could install with the command:\n" "\npip3 install -U funasr -i https://mirror.sjtu.edu.cn/pypi/web/simple" + ) from e model = AutoModel(model=model_dir) model_dir = model.export(type="onnx", quantize=quantize, **kwargs)