bugfix
This commit is contained in:
parent
620304378d
commit
fde9e893e0
48
app/checklang.py
Normal file
48
app/checklang.py
Normal file
@ -0,0 +1,48 @@
|
||||
import os
|
||||
from ahserver.webapp import webapp
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from appPublic.registerfunction import RegisterFunction
|
||||
|
||||
import fasttext
|
||||
|
||||
def docs(request):
|
||||
return """Check langage for text
|
||||
path: /v1/checklang
|
||||
method: POST
|
||||
headers:
|
||||
Content-Text: application/json
|
||||
|
||||
data:
|
||||
{
|
||||
"text": "what is language of this sentence? "
|
||||
}
|
||||
response:
|
||||
{
|
||||
"lang": "en"
|
||||
}
|
||||
"""
|
||||
def checklang(request, params_kw, *args, **kw):
|
||||
engine = kw.get('engine')
|
||||
text = params_kw.text
|
||||
pred = engine.predict(text)
|
||||
d = pred[0][0][9:]
|
||||
return {
|
||||
'lang':d
|
||||
}
|
||||
|
||||
def init():
|
||||
p = os.path.join(os.path.dirname(__file__), 'lid.176.ftz')
|
||||
print(f'model path={p}')
|
||||
model = fasttext.load_model(p)
|
||||
# 需先下载模型:https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz
|
||||
env = ServerEnv()
|
||||
env.engine = model
|
||||
rf = RegisterFunction()
|
||||
rf.register('checklang', checklang)
|
||||
|
||||
if __name__ == '__main__':
|
||||
rf = RegisterFunction()
|
||||
rf.register('checklang', checklang)
|
||||
rf.register('docs', docs)
|
||||
webapp(init)
|
||||
|
BIN
app/lid.176.ftz
Normal file
BIN
app/lid.176.ftz
Normal file
Binary file not shown.
28
conf/config.json
Executable file
28
conf/config.json
Executable file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"website":{
|
||||
"paths":[
|
||||
["$[workdir]$/wwwroot",""]
|
||||
],
|
||||
"client_max_size":10000,
|
||||
"host":"0.0.0.0",
|
||||
"port":9080,
|
||||
"coding":"utf-8",
|
||||
"indexes":[
|
||||
"index.html"
|
||||
],
|
||||
"startswiths":[
|
||||
{
|
||||
"leading":"/docs",
|
||||
"registerfunction":"docs"
|
||||
},{
|
||||
"leading":"/checklang",
|
||||
"registerfunction":"checklang"
|
||||
}
|
||||
],
|
||||
"processors":[
|
||||
[".tmpl","tmpl"]
|
||||
],
|
||||
"session_max_time":3000,
|
||||
"session_issue_time":2500
|
||||
}
|
||||
}
|
48
install.sh
Normal file
48
install.sh
Normal file
@ -0,0 +1,48 @@
|
||||
port=$1
|
||||
userid=$(id -un)
|
||||
groupid=$(id -gn)
|
||||
workdir=$(pwd)
|
||||
package=$(base $workdir)
|
||||
|
||||
cat <<EOF
|
||||
[Unit]
|
||||
Wants=systemd-networkd.service
|
||||
|
||||
[Service]
|
||||
User=$userid
|
||||
Group=$groupid
|
||||
WorkingDirectory=$workdir
|
||||
Type=forking
|
||||
ExecStart=$workdir/start.sh
|
||||
ExecStop=$workdir/stop.sh
|
||||
StandardOutput=append:/var/log/$package/$package.log
|
||||
StandardError=append:/var/log/$package/$package.log
|
||||
SyslogIdentifier=$package
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF > $workdir/$package.service
|
||||
|
||||
cat <<EOF
|
||||
|
||||
cat <<EOF
|
||||
#!/usr/bin/bash
|
||||
|
||||
$workdir/$package.env/bin/python $workdir/app/$package.py -p $port
|
||||
EOF > $workdir/start.sh
|
||||
|
||||
cat <<EOF
|
||||
#!/usr/bin/bash
|
||||
|
||||
ps -ef|grep "$package.py"|grep -v grep|awk '{print("kill -9", $2)}'|sh
|
||||
EOF > $workdir/stop.sh
|
||||
|
||||
chmod +x $workdir/*.sh
|
||||
python3 -m venv $package.env
|
||||
$package.env/bin/pip install -r requirements.txt
|
||||
sudo mkdir /var/log/$package
|
||||
sudo cp $package.service /etc/systemd/system
|
||||
sudo systemctl enable $package
|
||||
sudo systemctl start $package
|
||||
|
||||
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
fasttext
|
||||
git+https://git.kaiyauncloud.cn/yumoqing/apppublic
|
||||
git+https://git.kaiyauncloud.cn/yumoqing/sqlor
|
||||
git+https://git.kaiyauncloud.cn/yumoqing/ahserver
|
||||
|
0
wwwroot/index.html
Normal file
0
wwwroot/index.html
Normal file
Loading…
Reference in New Issue
Block a user