在python中Flask配置服务
################################################################################
################################################################################
from flask import Flask, request
from data_util import UtilsLTPTranslate
import json
model = UtilsLTPTranslate()
app = Flask(name)
@app.route("/")
def index():
return "翻译服务: 运行中"
@app.route("/LTPTranslate", methods=['POST', 'GET'])
def code():
text = request.form['text']
response = {}
data=[]
try:
if request.form['flag'] == 'companyName':
data.append(model.getEnCompanyName(text))
elif request.form['flag'] == 'address':
data.append(model.getEnAddress_2(text))
elif request.form['flag'] == 'common':
data.append(model.zh2en(text))
else:
data.append(model.zh2en(text))
response["data"] = data
except:
response["data"] = data
return json.dumps(response, ensure_ascii=False)
if name == 'main':
app.run(host="0.0.0.0", port="8005",processes=200)