|
|
@ -51,6 +51,33 @@ encoder, decoder, model, tokenizer = generatemodel.device_setup() |
|
|
|
autotitle = AutoTitle(encoder, decoder, model, tokenizer, start_id=0, end_id=tokenizer._token_end_id, maxlen=120) |
|
|
|
|
|
|
|
|
|
|
|
def smtp_f(name): |
|
|
|
# 在下面的代码行中使用断点来调试脚本。 |
|
|
|
import smtplib |
|
|
|
from email.mime.text import MIMEText |
|
|
|
from email.header import Header |
|
|
|
|
|
|
|
sender = '838878981@qq.com' # 发送邮箱 |
|
|
|
receivers = ['838878981@qq.com'] # 接收邮箱 |
|
|
|
auth_code = "jfqtutaiwrtdbcge" # 授权码 |
|
|
|
|
|
|
|
message = MIMEText('普通版降重项目出错,紧急', 'plain', 'utf-8') |
|
|
|
message['From'] = Header("Sender<%s>" % sender) # 发送者 |
|
|
|
message['To'] = Header("Receiver<%s>" % receivers[0]) # 接收者 |
|
|
|
|
|
|
|
subject = name |
|
|
|
message['Subject'] = Header(subject, 'utf-8') |
|
|
|
|
|
|
|
try: |
|
|
|
server = smtplib.SMTP_SSL('smtp.qq.com', 465) |
|
|
|
server.login(sender, auth_code) |
|
|
|
server.sendmail(sender, receivers, message.as_string()) |
|
|
|
print("邮件发送成功") |
|
|
|
server.close() |
|
|
|
except smtplib.SMTPException: |
|
|
|
print("Error: 无法发送邮件") |
|
|
|
|
|
|
|
|
|
|
|
class log: |
|
|
|
def __init__(self): |
|
|
|
pass |
|
|
@ -340,28 +367,32 @@ def classify(): # 调用模型,设置最大batch_size |
|
|
|
|
|
|
|
@app.route("/predict", methods=["POST"]) |
|
|
|
def handle_query(): |
|
|
|
print(request.remote_addr) |
|
|
|
texts = request.json["texts"] |
|
|
|
text_type = request.json["text_type"] |
|
|
|
if texts is None: |
|
|
|
return_text = {"texts": "输入了空值", "probabilities": None, "status_code": 402} |
|
|
|
return jsonify(return_text) |
|
|
|
if isinstance(texts, dict): |
|
|
|
id_ = str(uuid.uuid1()) # 为query生成唯一标识 |
|
|
|
print("uuid: ", uuid) |
|
|
|
d = {'id': id_, 'text': texts, "text_type": text_type} # 绑定文本和query id |
|
|
|
|
|
|
|
load_request_path = './request_data_logs/{}.json'.format(id_) |
|
|
|
with open(load_request_path, 'w', encoding='utf8') as f2: |
|
|
|
# ensure_ascii=False才能输入中文,否则是Unicode字符 |
|
|
|
# indent=2 JSON数据的缩进,美观 |
|
|
|
json.dump(d, f2, ensure_ascii=False, indent=4) |
|
|
|
redis_.rpush(db_key_query, json.dumps({"id": id_, "path": load_request_path})) # 加入redis |
|
|
|
redis_.sadd(db_key_querying, id_) |
|
|
|
return_text = {"texts": {'id': id_, }, "probabilities": None, "status_code": 200} |
|
|
|
print("ok") |
|
|
|
else: |
|
|
|
return_text = {"texts": "输入格式应该为字典", "probabilities": None, "status_code": 401} |
|
|
|
try: |
|
|
|
print(request.remote_addr) |
|
|
|
texts = request.json["texts"] |
|
|
|
text_type = request.json["text_type"] |
|
|
|
if texts is None: |
|
|
|
return_text = {"texts": "输入了空值", "probabilities": None, "status_code": 402} |
|
|
|
return jsonify(return_text) |
|
|
|
if isinstance(texts, dict): |
|
|
|
id_ = str(uuid.uuid1()) # 为query生成唯一标识 |
|
|
|
print("uuid: ", uuid) |
|
|
|
d = {'id': id_, 'text': texts, "text_type": text_type} # 绑定文本和query id |
|
|
|
|
|
|
|
load_request_path = './request_data_logs/{}.json'.format(id_) |
|
|
|
with open(load_request_path, 'w', encoding='utf8') as f2: |
|
|
|
# ensure_ascii=False才能输入中文,否则是Unicode字符 |
|
|
|
# indent=2 JSON数据的缩进,美观 |
|
|
|
json.dump(d, f2, ensure_ascii=False, indent=4) |
|
|
|
redis_.rpush(db_key_query, json.dumps({"id": id_, "path": load_request_path})) # 加入redis |
|
|
|
redis_.sadd(db_key_querying, id_) |
|
|
|
return_text = {"texts": {'id': id_, }, "probabilities": None, "status_code": 200} |
|
|
|
print("ok") |
|
|
|
else: |
|
|
|
return_text = {"texts": "输入格式应该为字典", "probabilities": None, "status_code": 401} |
|
|
|
except: |
|
|
|
return_text = {"texts": "项目出错", "probabilities": None, "status_code": 402} |
|
|
|
smtp_f("drop_weight_rewrite") |
|
|
|
return jsonify(return_text) # 返回结果 |
|
|
|
|
|
|
|
|
|
|
|