diff --git a/zmqfw.py b/app/fwasr.py similarity index 52% rename from zmqfw.py rename to app/fwasr.py index b101b47..32a5b6d 100644 --- a/zmqfw.py +++ b/app/fwasr.py @@ -1,35 +1,27 @@ import json import os -from appPublic.dictObject import DictObject -from appPublic.zmq_reqrep import ZmqReplier +from appPublic.worker import awaitify from appPublic.jsonConfig import getConfig +from ahserver.serverenv import ServerEnv +from ahserver.webapp import webapp from time import time from faster_whisper import WhisperModel -class ZmqASR: +class FWASR: def __init__(self): config = getConfig() - self.model_dir = config.model_dir or "large-v3" + self.modelname = config.modelname or "large-v3" self.device = config.device or "cpu" - self.zmq_url = config.zmq_url self.compute_type=config.compute_type or "float16" - self.model = WhisperModel(self.model_dir, + self.model = WhisperModel(self.modelname, device=self.device, compute_type=self.compute_type) - self.replier = ZmqReplier(self.zmq_url, self.generate) - def run(self): - print(f'running {self.zmq_url}') - self.replier._run() - print('ended ...') - - def generate(self, d): - msg= d.decode('utf-8') - data = DictObject(**json.loads(msg)) + def inference(self, audiofile): t1 = time() - segs, info = self.model.transcribe(data.audio_file) + segs, info = self.model.transcribe(audio_file) t2 = time() d = DictObject(**{ 'segments':[], @@ -45,13 +37,13 @@ class ZmqASR: d.segments.append(seg) d.content += s.text d.time_cost = t2 - t1 - print(f'{d}') - return json.dumps(d) + return d + +def init_func(): + asr = FWASR() + g = ServerEnv() + g.inference = awaitify(asr.inference) if __name__ == '__main__': - workdir = os.getcwd() - config = getConfig(workdir) - print(f'{config=}') - asr = ZmqASR() - print('here') - asr.run() + webapp(init_func) + diff --git a/conf/config.json b/conf/config.json index e9f2136..dbbdb3b 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,6 +1,48 @@ { - "zmq_url" : "tcp://127.0.0.1:10002", - "model_dir" : "large-v3", + "modelname" : "large-v3", "device" : "cuda", - "conpute_type": "float16" + "conpute_type": "float16", + "logger":{ + "name":"fwasr", + "levelname":"info", + "logfile":"$[workdir]$/logs/sage.log" + }, + "filesroot":"$[workdir]$/files", + "website":{ + "paths":[ + ["$[workdir]$/wwwroot",""] + ], + "client_max_size":10000, + "host":"0.0.0.0", + "port":10093, + "coding":"utf-8", + "indexes":[ + "index.html", + "index.tmpl", + "index.ui", + "index.dspy", + "index.md" + ], + "startswiths":[ + { + "leading":"/idfile", + "registerfunction":"idFileDownload" + } + ], + "processors":[ + [".dspy","dspy"], + [".md","md"] + ], + "session_max_time":3000, + "session_issue_time":2500, + "session_redis_notuse":{ + "url":"redis://127.0.0.1:6379" + } + }, + "langMapping":{ + "zh-Hans-CN":"zh-cn", + "zh-CN":"zh-cn", + "en-us":"en", + "en-US":"en" + } } diff --git a/files/README.md b/files/README.md new file mode 100644 index 0000000..e69de29 diff --git a/logs/stderr.log b/logs/stderr.log new file mode 100644 index 0000000..5c58845 --- /dev/null +++ b/logs/stderr.log @@ -0,0 +1,4 @@ +Traceback (most recent call last): + File "/data/ymq/py/fwasr/app/fwasr.py", line 6, in + from ahserver.serverenv import ServerEnv +ModuleNotFoundError: No module named 'ahserver' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f82924f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +git+https://git.kaiyuancloud.cn/yumoqing/apppublic +git+https://git.kaiyuancloud.cn/yumoqing/sqlor +git+https://git.kaiyuancloud.cn/yumoqing/ahserver diff --git a/script/fwasr.service b/script/fwasr.service new file mode 100644 index 0000000..d6f48c9 --- /dev/null +++ b/script/fwasr.service @@ -0,0 +1,11 @@ +[Unit] +Description=fwasr service +Wants=systemd-networkd.service +Requires=nginx.service + +[Service] +Type=forking +ExecStart=su - ymq -c "/data/ymq/py/fwasr/script/fwasr.sh" +ExecStop=su - ymq "/d/ymq/bin/killname fwasr.py" +[Install] +WantedBy=multi-user.target diff --git a/script/fwasr.sh b/script/fwasr.sh new file mode 100644 index 0000000..0928978 --- /dev/null +++ b/script/fwasr.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +killname /data/ymq/py/fwasr/app/fwasr.py +/d/ymq/ve/fw/bin/python /data/ymq/py/fwasr/app/fwasr.py -w /data/ymq/py/fwasr > /data/ymq/py/fwasr/logs/stderr.log 2>&1 & +exit 0 diff --git a/script/install.sh b/script/install.sh new file mode 100644 index 0000000..a08a3be --- /dev/null +++ b/script/install.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash +sudo cp fwasr.service /etc/systemd/system +sudo systemctl enable fwasr.service +sudo systemctl start fwasr diff --git a/wwwroot/index.dspy b/wwwroot/index.dspy new file mode 100644 index 0000000..e69de29 diff --git a/zmq_client.py b/zmq_client.py deleted file mode 100644 index 0f3f334..0000000 --- a/zmq_client.py +++ /dev/null @@ -1,42 +0,0 @@ -import json -import os - -from appPublic.dictObject import DictObject -from appPublic.zmq_reqrep import ZmqRequester -from appPublic.jsonConfig import getConfig - -zmq_url = "tcp://127.0.0.1:9999" -from time import time - -class ASRClient: - def __init__(self, zmq_url): - self.zmq_url = zmq_url - self.requester = ZmqRequester(self.zmq_url) - - def generate(self, audio_file): - d = { - "audio_file":audio_file - } - msg = json.dumps(d) - print(f'send={msg}') - resp = self.requester.send(msg) - if resp != None: - ret = json.loads(resp) - print(f'response={ret}') - else: - print(f'response is None') - - def run(self): - print(f'running {self.zmq_url}') - while True: - print('input audio_file:') - af = input() - if len(af) > 0: - self.generate(af) - print('ended ...') - -if __name__ == '__main__': - workdir = os.getcwd() - config = getConfig(workdir) - asr = ASRClient(config.zmq_url or zmq_url) - asr.run()