add get labels api
This commit is contained in:
parent
e73e573dd5
commit
0c185cbcfe
|
@ -29,8 +29,6 @@ def query_file():
|
||||||
if 'anno.json' in file_names:
|
if 'anno.json' in file_names:
|
||||||
file_names.remove('anno.json')
|
file_names.remove('anno.json')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
|
||||||
|
|
||||||
# 判断路径是否存在
|
# 判断路径是否存在
|
||||||
|
@ -42,7 +40,8 @@ def query_file():
|
||||||
ret_info.info.append(file_info)
|
ret_info.info.append(file_info)
|
||||||
print(2)
|
print(2)
|
||||||
else:
|
else:
|
||||||
for file_name in sorted(file_names)[(page_number - 1) * page_size: (page_number - 1) * page_size + page_size]:
|
for file_name in sorted(file_names)[
|
||||||
|
(page_number - 1) * page_size: (page_number - 1) * page_size + page_size]:
|
||||||
file_info = FileInfo()
|
file_info = FileInfo()
|
||||||
file_info.fileName = file_name
|
file_info.fileName = file_name
|
||||||
|
|
||||||
|
@ -62,6 +61,33 @@ def query_file():
|
||||||
return json.dumps(ret_info, default=lambda o: o.__dict__)
|
return json.dumps(ret_info, default=lambda o: o.__dict__)
|
||||||
|
|
||||||
|
|
||||||
|
@api.route('/get_labels', methods=['GET'])
|
||||||
|
def get_lables():
|
||||||
|
ret_info = ReturnInfo()
|
||||||
|
try:
|
||||||
|
project_name = request.args.get("projectName")
|
||||||
|
# current_filename = request.args.get("current_filename")
|
||||||
|
download_json = []
|
||||||
|
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
|
||||||
|
print(len(anno_data))
|
||||||
|
for item in anno_data:
|
||||||
|
|
||||||
|
item_dict = {'file': item['fileName'],
|
||||||
|
'text': read_txt_file(PROJECT_PATH.format(project_name) + '/' + item['fileName']),
|
||||||
|
'labels': list(set([x['type'] for x in item["annoDetails"]]))}
|
||||||
|
print(item_dict)
|
||||||
|
download_json.append(item_dict)
|
||||||
|
# for detail in item["annoDetails"]:
|
||||||
|
# label_set = set()
|
||||||
|
# label_set.add(detail['type'])
|
||||||
|
# item_dict['labels'] = list(label_set)
|
||||||
|
# download_json.append(item_dict)
|
||||||
|
# print(download_json)
|
||||||
|
except Exception as e:
|
||||||
|
ret_info.errCode = 404
|
||||||
|
ret_info.errMsg = str(e)
|
||||||
|
return json.dumps(download_json, default=lambda o: o.__dict__)
|
||||||
|
|
||||||
@api.route('/get_json', methods=['GET'])
|
@api.route('/get_json', methods=['GET'])
|
||||||
def get_json():
|
def get_json():
|
||||||
ret_info = ReturnInfo()
|
ret_info = ReturnInfo()
|
||||||
|
@ -102,6 +128,7 @@ def get_json():
|
||||||
response = make_response(send_from_directory(directory='', path=DOWNLOAD_FILE_LOCATION.format(project_name),
|
response = make_response(send_from_directory(directory='', path=DOWNLOAD_FILE_LOCATION.format(project_name),
|
||||||
as_attachment=True))
|
as_attachment=True))
|
||||||
response.headers["Content-disposition"] = 'attachment; filename=result.json'
|
response.headers["Content-disposition"] = 'attachment; filename=result.json'
|
||||||
|
|
||||||
# print(PROJECT_PATH.format(project_name)+'/result.json')
|
# print(PROJECT_PATH.format(project_name)+'/result.json')
|
||||||
# os.remove(PROJECT_PATH.format(project_name)+'/result.json')
|
# os.remove(PROJECT_PATH.format(project_name)+'/result.json')
|
||||||
|
|
||||||
|
@ -109,6 +136,7 @@ def get_json():
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
os.remove(PROJECT_PATH.format(project_name) + '/result.json')
|
os.remove(PROJECT_PATH.format(project_name) + '/result.json')
|
||||||
print('result.json has been deleted')
|
print('result.json has been deleted')
|
||||||
|
|
||||||
thread = threading.Thread(target=delete)
|
thread = threading.Thread(target=delete)
|
||||||
thread.start()
|
thread.start()
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
[{"fileName": "first.txt", "annoDetails": [{"name": "是一个测", "type": "test1", "start": 1, "end": 5, "isSmall": false}, {"name": "测", "type": "test2", "start": 4, "end": 5, "isSmall": true}, {"name": "文", "type": "test2", "start": 6, "end": 7}], "isAnno": true}, {"fileName": "second.txt", "annoDetails": [{"name": "点亮", "type": "test1", "start": 2, "end": 4}], "isAnno": true}, {"fileName": "test.txt", "annoDetails": [{"name": "一种信", "type": "test1", "start": 3, "end": 6}], "isAnno": true}, {"fileName": "txt.txt", "annoDetails": [{"name": "试文件", "type": "test1", "start": 5, "end": 8}], "isAnno": true}]
|
[ {"fileName": "test.txt", "annoDetails": [{"name": "开源是一", "type": "test1", "start": 0, "end": 4, "isSmall": false}, {"name": "一种信", "type": "test1", "start": 3, "end": 6, "isSmall": true}, {"name": "仰", "type": "test3", "start": 6, "end": 7}], "isAnno": true}, {"fileName": "first.txt", "annoDetails": [{"name": "是一个测", "type": "test1", "start": 1, "end": 5, "isSmall": false}, {"name": "测试文本", "type": "test1", "start": 4, "end": 8}, {"name": "测", "type": "test2", "start": 4, "end": 5, "isSmall": true}, {"name": "文", "type": "test2", "start": 6, "end": 7, "isSmall": false}], "isAnno": true}, {"fileName": "新建文本文档 - 副本 (5).txt", "annoDetails": [{"name": "这是", "type": "test1", "start": 0, "end": 2, "isSmall": false}, {"name": "个新", "type": "test2", "start": 3, "end": 5, "isSmall": false}, {"name": "文件\n", "type": "test3", "start": 6, "end": 9}], "isAnno": true}, {"fileName": "新建文本文档 - 副本 (2).txt", "annoDetails": [{"name": "这是一个新", "type": "test3", "start": 0, "end": 5}, {"name": "一个", "type": "test1", "start": 2, "end": 4, "isSmall": false}, {"name": "个新增", "type": "test1", "start": 3, "end": 6, "isSmall": true}, {"name": "新增文件", "type": "test1", "start": 4, "end": 8, "isSmall": true}], "isAnno": true}, {"fileName": "新建文本文档 - 副本.txt", "annoDetails": [{"name": "新增文", "type": "test3", "start": 4, "end": 7}], "isAnno": true}, {"fileName": "second.txt", "annoDetails": [{"name": "开源点", "type": "test1", "start": 0, "end": 3}, {"name": "点亮世", "type": "test3", "start": 2, "end": 5, "isSmall": false}, {"name": "点亮", "type": "test1", "start": 2, "end": 4, "isSmall": true}, {"name": "亮世界", "type": "test1", "start": 3, "end": 6, "isSmall": true}], "isAnno": true}]
|
|
@ -5,4 +5,5 @@
|
||||||
| v1/project/get_zipped_data | POST | projectName:项目名 file:数据集文件(目前只支持.zip格式) | json :errcode表示是否成功导入 |
|
| v1/project/get_zipped_data | POST | projectName:项目名 file:数据集文件(目前只支持.zip格式) | json :errcode表示是否成功导入 |
|
||||||
| v1/files/get_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
| v1/files/get_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
||||||
|v1/project/delete_program |GET |projectName:项目名|json:errcode表示是否成功|
|
|v1/project/delete_program |GET |projectName:项目名|json:errcode表示是否成功|
|
||||||
|
| v1/files//get_labels | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue