代码拉取完成,页面将自动刷新
from flask import Flask
from flask import request
from datetime import datetime, timezone
import mysql.connector
import json
import os
app = Flask(__name__)
cnx_local = mysql.connector.connect(
user=os.environ["CLIENTDB_USERNAME"],
password=os.environ["CLIENTDB_PASSWORD"],
host=os.environ["CLIENTDB_HOST"],
database=os.environ["CLIENTDB_SCHEMA"]
)
cnx_main = mysql.connector.connect(
user=os.environ["MAINDB_USERNAME"],
password=os.environ["MAINDB_PASSWORD"],
host=os.environ["MAINDB_HOST"],
database=os.environ["MAINDB_SCHEMA"]
)
@app.route("/detect", methods=["POST"])
def detect():
hyp = json.loads(request.json["hyperparam"])
model_id = int(hyp["modelid"])
data_id = int(hyp["datasetid"])
job_id = int(request.json["jobid"])
cur_time = datetime.now(tz=timezone.utc)
exc_state = "INSERT INTO job_status (id_job, status, create_time, update_time) VALUES (%s, %s, %s, %s)"
exc_val = (job_id, "working", cur_time, cur_time)
cursor = cnx_main.cursor()
cursor.execute(exc_state, exc_val)
cnx_main.commit()
cursor.close()
os.system(f"nohup python -u main_predict.py --jobid {job_id} --modelid {model_id} --datasetid {data_id} >> client_out.log 2>&1 &")
return "Job started!"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。