feat(自动标注): 引入auto_anno_2,支持文本分类、实体抽取接口
This commit is contained in:
parent
3e41a34d8a
commit
a11af98ee5
|
@ -1,5 +1,5 @@
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
from ...api.v1 import index, project, files, anno
|
from ...api.v1 import index, project, files, anno, ai
|
||||||
|
|
||||||
|
|
||||||
def create_blueprint_v1():
|
def create_blueprint_v1():
|
||||||
|
@ -9,5 +9,6 @@ def create_blueprint_v1():
|
||||||
project.api.register(bp_v1, url_prefix='/project')
|
project.api.register(bp_v1, url_prefix='/project')
|
||||||
anno.api.register(bp_v1, url_prefix='/anno')
|
anno.api.register(bp_v1, url_prefix='/anno')
|
||||||
files.api.register(bp_v1, url_prefix='/files')
|
files.api.register(bp_v1, url_prefix='/files')
|
||||||
|
ai.api.register(bp_v1, url_prefix='/ai')
|
||||||
|
|
||||||
return bp_v1
|
return bp_v1
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
from app.libs.redprint import RedPrint
|
||||||
|
import time
|
||||||
|
from flask import request
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ...libs.tools import read_file, write_json, read_json_file, make_dir
|
||||||
|
|
||||||
|
import auto_anno_2 as aa
|
||||||
|
|
||||||
|
api = RedPrint('ai')
|
||||||
|
|
||||||
|
class ReturnInfo:
|
||||||
|
def __init__(self):
|
||||||
|
self.errCode = 0
|
||||||
|
self.errMsg = ''
|
||||||
|
self.info = []
|
||||||
|
|
||||||
|
@api.route('/nlp/cls', methods=['POST'])
|
||||||
|
def nlp_cls():
|
||||||
|
ret_info = ReturnInfo()
|
||||||
|
try:
|
||||||
|
j = request.get_json()
|
||||||
|
texts = j['texts']
|
||||||
|
types = j['types']
|
||||||
|
annos = []
|
||||||
|
for text in texts:
|
||||||
|
anno = aa.cls(text, types)
|
||||||
|
annos.append(anno)
|
||||||
|
ret_info.info = annos
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
ret_info.errCode = 404
|
||||||
|
ret_info.errMsg = str(e)
|
||||||
|
|
||||||
|
return ret_info.__dict__
|
||||||
|
|
||||||
|
@api.route('/nlp/ner', methods=['POST'])
|
||||||
|
def nlp_ner():
|
||||||
|
ret_info = ReturnInfo()
|
||||||
|
try:
|
||||||
|
j = request.get_json()
|
||||||
|
texts = j['texts']
|
||||||
|
types = j['types']
|
||||||
|
annos = []
|
||||||
|
for text in texts:
|
||||||
|
anno = aa.ner(text, types)
|
||||||
|
annos.append(anno)
|
||||||
|
ret_info.info = annos
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
ret_info.errCode = 404
|
||||||
|
ret_info.errMsg = str(e)
|
||||||
|
|
||||||
|
return ret_info.__dict__
|
|
@ -0,0 +1,2 @@
|
||||||
|
flask
|
||||||
|
auto_anno_2
|
Loading…
Reference in New Issue