Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server]added engine framework #1383

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions speechserving/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
13 changes: 13 additions & 0 deletions speechserving/speechserving/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
16 changes: 10 additions & 6 deletions speechserving/speechserving/bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import argparse



def init(args):
""" 系统初始化
"""
Expand All @@ -27,13 +26,18 @@ def main(args):
app.run(host='0.0.0.0', port=conf.port)



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config_file", action="store",
help="yaml file of the app", default="./conf/application.yaml")
parser.add_argument("--log_file", action="store",
help="log file", default="./log/paddlespeech.log")
parser.add_argument(
"--config_file",
action="store",
help="yaml file of the app",
default="./conf/application.yaml")
parser.add_argument(
"--log_file",
action="store",
help="log file",
default="./log/paddlespeech.log")
args = parser.parse_args()

main(args)
16 changes: 10 additions & 6 deletions speechserving/speechserving/bin/paddlespeech-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import argparse



def init(args):
""" 系统初始化
"""
Expand All @@ -27,13 +26,18 @@ def main(args):
app.run(host='0.0.0.0', port=conf.port)



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config_file", action="store",
help="yaml file of the app", default="./conf/application.yaml")
parser.add_argument("--log_file", action="store",
help="log file", default="./log/paddlespeech.log")
parser.add_argument(
"--config_file",
action="store",
help="yaml file of the app",
default="./conf/application.yaml")
parser.add_argument(
"--log_file",
action="store",
help="log file",
default="./log/paddlespeech.log")
args = parser.parse_args()

main(args)
16 changes: 10 additions & 6 deletions speechserving/speechserving/bin/paddlespeech-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import argparse



def init(args):
""" 系统初始化
"""
Expand All @@ -27,13 +26,18 @@ def main(args):
app.run(host='0.0.0.0', port=conf.port)



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config_file", action="store",
help="yaml file of the app", default="./conf/application.yaml")
parser.add_argument("--log_file", action="store",
help="log file", default="./log/paddlespeech.log")
parser.add_argument(
"--config_file",
action="store",
help="yaml file of the app",
default="./conf/application.yaml")
parser.add_argument(
"--log_file",
action="store",
help="log file",
default="./log/paddlespeech.log")
args = parser.parse_args()

main(args)
8 changes: 8 additions & 0 deletions speechserving/speechserving/conf/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is the parameter configuration file for PaddleSpeech Serving.

##################################################################
# SERVER SETTING #
##################################################################
host: '0.0.0.0'
port: 8090

13 changes: 13 additions & 0 deletions speechserving/speechserving/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
17 changes: 10 additions & 7 deletions speechserving/speechserving/engine/asr/python/asr_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
# 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.
from engine import BaseEngine
from engine.base_engine import BaseEngine

from utils.log import logger

__all__ = ['ASREngine']

class ASREngine(BaseEngine):

def __init__(self, name):
class ASREngine(BaseEngine):
def __init__(self, name=None):
super(ASREngine, self).__init__()

self.executor = name
self.input = None
self.output = None

def init(self):
pass
Expand All @@ -28,8 +32,8 @@ def postprocess(self):
pass

def run(self):
pass

logger.info("start run asr engine")
return "hello world"


if __name__ == "__main__":
Expand All @@ -39,4 +43,3 @@ def run(self):
print(class1 is class2)
print(id(class1))
print(id(class2))

1 change: 1 addition & 0 deletions speechserving/speechserving/engine/base_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from pattern_singleton import Singleton


class BaseEngine(metaclass=Singleton):
"""
An base engine class
Expand Down
42 changes: 33 additions & 9 deletions speechserving/speechserving/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,55 @@
# limitations under the License.
import argparse

import asr_api as api_run
import tts_api as api_run
import uvicorn
import yaml
from engine.asr.python.asr_engine import ASREngine
from fastapi import FastAPI
from restful.api import router as api_router

from utils.log import logger

app = FastAPI(
title="PaddleSpeech Serving API", description="Api", version="0.0.1")


def init(args):
""" 系统初始化
"""
app.include_router(api_router)

# engine single
ASR_ENGINE = ASREngine("asr")

# todo others

return True


def main(args):
"""主程序入口"""

if init(args):
api_run.run()
app.run(host='0.0.0.0', port=conf.port)
#TODO configuration
from yacs.config import CfgNode
with open(args.config_file, 'rt') as f:
config = CfgNode(yaml.safe_load(f))

if init(args):
uvicorn.run(app, host=config.host, port=config.port, debug=True)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--config_file", action="store",
help="yaml file of the app", default="./conf/application.yaml")
parser.add_argument("--log_file", action="store",
help="log file", default="./log/paddlespeech.log")
parser.add_argument(
"--config_file",
action="store",
help="yaml file of the app",
default="./conf/application.yaml")
parser.add_argument(
"--log_file",
action="store",
help="log file",
default="./log/paddlespeech.log")
args = parser.parse_args()

main(args)
13 changes: 13 additions & 0 deletions speechserving/speechserving/restful/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
20 changes: 5 additions & 15 deletions speechserving/speechserving/restful/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@
# limitations under the License.
from fastapi import APIRouter

router = APIRouter()


router.include_router(auth_router)
router.include_router(user_router)
router.include_router(profile_router)
router.include_router(comment_router)
router.include_router(article_router)
router.include_router(tag_router)

from .asr_api import router as asr_router
from .tts_api import router as tts_router



def init_app(app):

app.include_router(router)
router = APIRouter()
router.include_router(asr_router)
router.include_router(tts_router)
63 changes: 63 additions & 0 deletions speechserving/speechserving/restful/asr_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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.
from fastapi import APIRouter
import base64


from engine.asr.python.asr_engine import ASREngine
from .response import ASRResponse
from .request import ASRRequest

router = APIRouter()


@router.get('/paddlespeech/asr/help')
def help():
"""help

Returns:
json: [description]
"""
return {'hello': 'world'}


@router.post("/paddlespeech/asr", response_model=ASRResponse)
def asr(request_body: ASRRequest):
"""asr api

Args:
request_body (ASRRequest): [description]

Returns:
json: [description]
"""
# single
asr_engine = ASREngine()

asr_engine.init()
asr_results = asr_engine.run()
asr_engine.postprocess()

json_body = {
"success": True,
"code": 0,
"message": {
"description": "success"
},
"result": {
"transcription": asr_results
}
}

return json_body
10 changes: 5 additions & 5 deletions speechserving/speechserving/restful/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
# 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.
from typing import Optional
from typing import List
from typing import Optional

from pydantic import BaseModel


__all__ = ['ASRRequest, TTSRequest']


#****************************************************************************************/
#************************************ ASR request ***************************************/
#****************************************************************************************/
Expand All @@ -29,8 +29,8 @@ class ASRRequest(BaseModel):
"audio": "exSI6ICJlbiIsCgkgICAgInBvc2l0aW9uIjogImZhbHNlIgoJf...",
"audio_format": "wav",
"sample_rate": 16000,
"lang ": "zh_cn",
"ptt ":false
"lang": "zh_cn",
"ptt":false
}
"""
audio: str
Expand All @@ -53,4 +53,4 @@ class TTSRequest(BaseModel):
"lang ": "zh_cn",
"ptt ":false
}
"""
"""
Loading