diff --git a/be/app/api/v1/project.py b/be/app/api/v1/project.py index ac4636b..b84e53e 100644 --- a/be/app/api/v1/project.py +++ b/be/app/api/v1/project.py @@ -67,6 +67,41 @@ def get_zipped_data(): return json.dumps(ret_info, default=lambda o: o.__dict__) +@api.route('/get_jsonl_data', methods=['POST']) +def get_jsonl_data(): + ret_info = ReturnInfo() + try: + project_name = request.form.get('projectName') + + upload_file = request.files['file'] + file_path = os.path.join(PROJECT_PATH.format(project_name), upload_file.filename) + file_name = upload_file.filename.replace('.jsonl', '') + target_path = PROJECT_PATH.format(project_name) + '/data' + upload_file.save(file_path) + + with open(file_path, 'r', encoding='utf-8') as fh: + l = fh.readline().strip() + idx = 0 + while l: + idx += 1 + j = json.loads(l) + txts = [] + for key in j: + txts.append(j[key]) + _idx = ('000000'+str(idx))[-6:] + if len(str(idx)) > 6: + _idx = str(idx) + open(f'{target_path}/{file_name}_{_idx}', 'w', encoding='utf-8').write(''.join(txts)) + l = fh.readline().strip() + os.remove(file_path) + + except Exception as e: + print(e) + ret_info.errCode = 404 + ret_info.errMsg = str(e) + + return json.dumps(ret_info, default=lambda o: o.__dict__) + @api.route('/create', methods=['POST']) def create_project(): diff --git a/be/app/libs/tools.py b/be/app/libs/tools.py index 142a068..5bf3c13 100644 --- a/be/app/libs/tools.py +++ b/be/app/libs/tools.py @@ -41,6 +41,8 @@ def read_file(file_path): return read_img_file(file_path) elif ext in ['txt', 'json']: return read_txt_file(file_path) + elif '.' not in file_path: + return read_txt_file(file_path) return '' # 读取img文件 diff --git a/fe/src/components/NLP/rlhf.vue b/fe/src/components/NLP/rlhf.vue index 220d8d7..f50fe31 100644 --- a/fe/src/components/NLP/rlhf.vue +++ b/fe/src/components/NLP/rlhf.vue @@ -1,6 +1,6 @@