Files
fcb_photo_review/services/paddle_services/clas_text.py

29 lines
821 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging.config
from flask import Flask, request
from paddlenlp import Taskflow
from log import LOGGING_CONFIG
from utils import process_request
app = Flask(__name__)
schema = ['基本医保结算单', '出院记录', '费用清单']
CLAS = Taskflow('zero_shot_text_classification', model='utc-xbase', schema=schema,
task_path='model/text_classification', precision='fp16')
@app.route('/', methods=['POST'])
@process_request
def main():
text = request.form.get('text')
cls_result = CLAS(text)
cls_result = cls_result[0].get('predictions')[0]
if cls_result['score'] < 0.8:
raise Exception(f'识别结果置信度过低text: {text}')
return cls_result['label']
if __name__ == '__main__':
logging.config.dictConfig(LOGGING_CONFIG)
app.run('0.0.0.0', 5008)