You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.0 KiB
52 lines
2.0 KiB
4 months ago
|
# from paddlenlp import Taskflow
|
||
|
#checkPlaceNameServer
|
||
|
# tagTask1 = Taskflow("ner",device_id=2,precision='fp16')##checkPlaceName
|
||
|
# from flask import Flask, request, jsonify
|
||
|
from fastapi import FastAPI, Request
|
||
|
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
||
|
import uvicorn
|
||
|
from fastapi.responses import JSONResponse
|
||
|
from pydantic import BaseModel
|
||
|
app = FastAPI()
|
||
|
|
||
|
import sys
|
||
|
sys.path.append("..")
|
||
|
from ner_model import NERModel
|
||
|
# model = NERModel("bert", "shibing624/bert4ner-base-chinese")
|
||
|
model = NERModel("bertspan", "shibing624/bertspan4ner-base-chinese",cuda_device=5)
|
||
|
class RequestData(BaseModel):
|
||
|
data: dict
|
||
|
@app.post("/taskflow/checkPlaceNameServer")
|
||
|
async def process_request(request: RequestData):
|
||
|
global model
|
||
|
# 提取文本数据
|
||
|
text_data = request.data.get('text')
|
||
|
# 处理文本数据,例如检查错误等
|
||
|
# 这里您可以添加实际的逻辑来检查文档错误
|
||
|
predictions, raw_outputs, entities = model.predict(text_data)
|
||
|
|
||
|
# 返回响应
|
||
|
return JSONResponse(content={"status": "success", "data": entities}, status_code=200)
|
||
|
if __name__ == "__main__":
|
||
|
uvicorn.run(app, host="0.0.0.0", port=8191)
|
||
|
# # 创建一个锁对象
|
||
|
# import threading
|
||
|
# app = Flask(__name__)
|
||
|
# lock = threading.Lock()
|
||
|
# #多线程但是每次只处理一个请求,多余的请求需要排队
|
||
|
# @app.route('/taskflow/checkPlaceNameServer', methods=['POST'])
|
||
|
# def process_request():
|
||
|
# with lock:
|
||
|
# data = request.get_json()
|
||
|
# # print("data",data)
|
||
|
# # 提取文本数据
|
||
|
# text_data = data.get('data', {}).get('text')
|
||
|
# # 处理文本数据,例如检查错误等
|
||
|
# # 这里您可以添加实际的逻辑来检查文档错误
|
||
|
# predictions, raw_outputs, entities =model.predict(text_data)
|
||
|
# # 示例:简单打印接收到的文本
|
||
|
# # # 返回响应
|
||
|
# return jsonify({"status": "success", "data": entities}), 200
|
||
|
|
||
|
# if __name__ == '__main__':
|
||
|
# app.run(threaded=True,port=8191)
|