asr/app/asr.py

42 lines
1.3 KiB
Python
Raw Normal View History

2024-08-03 17:27:14 +08:00
import os, sys
import argparse
from appPublic.log import MyLogger, info, debug, warning
from appPublic.folderUtils import ProgramPath
from appPublic.jsonConfig import getConfig
2024-08-03 19:04:42 +08:00
from appPublic.registerfunction import RegisterFunction
2024-08-03 17:27:14 +08:00
from ahserver.configuredServer import ConfiguredServer
2024-08-03 17:57:04 +08:00
from ahserver.serverenv import ServerEnv
2024-08-06 15:56:45 +08:00
from whisper_model import WhisperFile
2024-08-03 19:04:42 +08:00
from asr_engine import generate
2024-08-03 17:27:14 +08:00
__version__ = '0.0.1'
if __name__ == '__main__':
2024-08-03 17:57:04 +08:00
parser = argparse.ArgumentParser(prog="Sage")
parser.add_argument('-w', '--workdir')
parser.add_argument('-p', '--port')
args = parser.parse_args()
print(args)
workdir = args.workdir or os.getcwd()
p = ProgramPath()
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
if config.logger:
logger = MyLogger(config.logger.name or 'sage',
levelname=config.logger.levelname or 'debug',
logfile=config.logger.logfile or None)
else:
logger = MyLogger('sage', levelname='debug')
2024-08-03 17:27:14 +08:00
2024-08-03 17:57:04 +08:00
info(f'========sage version={__version__}========')
# server = ConfiguredServer(auth_klass=MyAuthAPI, workdir=workdir)
server = ConfiguredServer(workdir=workdir)
2024-08-03 19:04:42 +08:00
rf = RegisterFunction()
rf.register('generate', generate)
2024-08-03 19:11:31 +08:00
info(f'{rf.registKW=}')
2024-08-03 17:57:04 +08:00
g = ServerEnv()
2024-08-04 18:50:57 +08:00
g.whisper_engine = WhisperBase64()
2024-08-03 17:57:04 +08:00
port = args.port or config.website.port or 8080
port = int(port)
server.run(port=port)
2024-08-03 17:27:14 +08:00