43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
'''
|
||
Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
||
Date: 2023-03-29 20:22:34
|
||
LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
|
||
LastEditTime: 2023-04-05 15:27:13
|
||
FilePath: /luyuetong-data/yolox-pytorch/flask_on.py
|
||
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://githaub.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||
'''
|
||
import os
|
||
|
||
from flask import Flask, request, jsonify
|
||
from gevent import pywsgi
|
||
|
||
from predict import PREDICT
|
||
|
||
app = Flask(__name__)
|
||
# 设置未处理文件路径以及处理保存路径
|
||
# dataPath = '/home/DiatomRecognition/upload'
|
||
# resultPath = '/home/DiatomRecognition/result'
|
||
# localhost 测试
|
||
dataPath = 'E:/Document/project/temp/data'
|
||
resultPath = r'E:\Document\project\temp/save'
|
||
|
||
|
||
@app.route('/predict', methods=['POST'])
|
||
def predict_one():
|
||
if not os.path.exists(resultPath):
|
||
# 如果不存在,创建文件夹及其所有父文件夹
|
||
os.makedirs(resultPath)
|
||
# 从请求参数中提取文件名
|
||
fileName = request.form['fileName']
|
||
# 将文件路径传递给模型进行预测
|
||
result = PREDICT(dataPath, resultPath, fileName) # predicted_class,score如果需要再处理
|
||
|
||
return result
|
||
|
||
|
||
if __name__ == '__main__':
|
||
# app.debug = False
|
||
server = pywsgi.WSGIServer(('0.0.0.0', 2000), app)
|
||
app.config["JSON_AS_ASCII"] = False
|
||
server.serve_forever()
|