未验证 提交 c3c30285 编写于 作者: 文幕地方's avatar 文幕地方 提交者: GitHub

rm paddlenlp and paddlespeech in requirements.txt (#5688)

* fix re error

* add hit in PPStructure

* rm paddlenlp and paddlespeech in requirements.txt

* add auto install of module
上级 089dea74
...@@ -18,11 +18,11 @@ import os ...@@ -18,11 +18,11 @@ import os
import numpy as np import numpy as np
import math import math
import paddle import paddle
from paddlenlp import Taskflow
from ..base import ModelBaseOp from ..base import ModelBaseOp
from ppcv.ops.base import create_operators, BaseOp from ppcv.ops.base import create_operators, BaseOp
from ppcv.core.workspace import register from ppcv.core.workspace import register
from ppcv.utils.utility import check_install
from .postprocess import * from .postprocess import *
...@@ -43,6 +43,8 @@ class SentimentAnalysisOp(BaseOp): ...@@ -43,6 +43,8 @@ class SentimentAnalysisOp(BaseOp):
self._init_task(model_cfg) self._init_task(model_cfg)
def _init_task(self, model_cfg): def _init_task(self, model_cfg):
check_install('paddlenlp', 'paddlenlp')
from paddlenlp import Taskflow
task = model_cfg.get('task', 'sentiment_analysis') task = model_cfg.get('task', 'sentiment_analysis')
self.nlp = Taskflow(task) self.nlp = Taskflow(task)
...@@ -123,6 +125,8 @@ class InformationExtractionOp(SentimentAnalysisOp): ...@@ -123,6 +125,8 @@ class InformationExtractionOp(SentimentAnalysisOp):
self._init_task(model_cfg) self._init_task(model_cfg)
def _init_task(self, model_cfg): def _init_task(self, model_cfg):
check_install('paddlenlp', 'paddlenlp')
from paddlenlp import Taskflow
task = model_cfg.get('task', 'information_extraction') task = model_cfg.get('task', 'information_extraction')
schema = model_cfg.get('schema', ['时间', '地点', '人物']) schema = model_cfg.get('schema', ['时间', '地点', '人物'])
self.nlp = Taskflow(task, schema=schema) self.nlp = Taskflow(task, schema=schema)
......
...@@ -15,16 +15,19 @@ ...@@ -15,16 +15,19 @@
import importlib import importlib
import pathlib import pathlib
import os import os
from paddlespeech.cli.tts import TTSExecutor
from ppcv.ops.base import create_operators, BaseOp from ppcv.ops.base import create_operators, BaseOp
from ppcv.core.workspace import register from ppcv.core.workspace import register
from ppcv.utils.utility import check_install
@register @register
class TTSOp(BaseOp): class TTSOp(BaseOp):
def __init__(self, model_cfg, env_cfg): def __init__(self, model_cfg, env_cfg):
super(TTSOp, self).__init__(model_cfg, env_cfg) super(TTSOp, self).__init__(model_cfg, env_cfg)
check_install('paddlespeech', 'paddlespeech')
from paddlespeech.cli.tts import TTSExecutor
mod = importlib.import_module(__name__) mod = importlib.import_module(__name__)
env_cfg["batch_size"] = model_cfg.get("batch_size", 1) env_cfg["batch_size"] = model_cfg.get("batch_size", 1)
self.batch_size = env_cfg["batch_size"] self.batch_size = env_cfg["batch_size"]
......
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib.util
import sys
import subprocess
def check_install(module_name, install_name):
spec = importlib.util.find_spec(module_name)
if spec is None:
print(f'Warnning! The {module_name} module is NOT installed')
print(
f'Try install {module_name} module automatically. You can also try to install manually by pip install {install_name}.'
)
python = sys.executable
try:
subprocess.check_call(
[python, '-m', 'pip', 'install', install_name],
stdout=subprocess.DEVNULL)
print(f'The {module_name} module is now installed')
except subprocess.CalledProcessError as exc:
raise Exception(
f"Install {module_name} failed, please install manually")
else:
print(f"{module_name} has been installed.")
...@@ -4,8 +4,6 @@ opencv-contrib-python ...@@ -4,8 +4,6 @@ opencv-contrib-python
PyYAML>=5.1 PyYAML>=5.1
Pillow Pillow
faiss-cpu==1.7.1.post2 faiss-cpu==1.7.1.post2
paddlenlp
paddlespeech
pycocotools pycocotools
filterpy filterpy
shapely shapely
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册