From 972028ab9daf2387a6abf43e7fe7f9b89a216a76 Mon Sep 17 00:00:00 2001
From: maxmon <541182180@qq.com>
Date: Sat, 16 Apr 2022 12:51:25 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=9B=BE=E7=89=87?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=B9=B6=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
be/app/api/v1/anno.py | 4 ++--
be/app/api/v1/project.py | 2 +-
be/app/libs/tools.py | 15 +++++++++++++++
fe/config/index.js | 4 ++--
fe/src/components/NER/index.vue | 9 +++++++++
fe/src/components/home/index.vue | 1 +
6 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/be/app/api/v1/anno.py b/be/app/api/v1/anno.py
index 86e235b..76511ce 100644
--- a/be/app/api/v1/anno.py
+++ b/be/app/api/v1/anno.py
@@ -7,7 +7,7 @@ import json
import os
import zipfile
-from ...libs.tools import read_txt_file, write_json, read_json_file, make_dir
+from ...libs.tools import read_file, write_json, read_json_file, make_dir
api = RedPrint('anno')
@@ -59,7 +59,7 @@ def query_anno():
file_name = request.args.get("fileName").strip()
file_path = PROJECTS + '/' + project_name + '/' + file_name
- file_content = read_txt_file(file_path)
+ file_content = read_file(file_path)
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
output_anno = OutputAnno()
diff --git a/be/app/api/v1/project.py b/be/app/api/v1/project.py
index 86f91de..b84f6b7 100644
--- a/be/app/api/v1/project.py
+++ b/be/app/api/v1/project.py
@@ -53,7 +53,7 @@ def get_zipped_data():
folder_path = target_path + '/' + item
if os.path.isdir(folder_path):
for file in os.listdir(folder_path):
- if file.split('.')[-1] == 'txt':
+ if file.split('.')[-1] in ['txt', 'jpg', 'png']:
shutil.copy(folder_path + '/' + file, folder_path + '/../')
# Here to deal with chinese encode in module zipfile and rarfile
if file_type == 'zip':
diff --git a/be/app/libs/tools.py b/be/app/libs/tools.py
index aec60b9..b450f0d 100644
--- a/be/app/libs/tools.py
+++ b/be/app/libs/tools.py
@@ -8,6 +8,7 @@ import tarfile
from os import rename
from os import listdir
from shutil import move
+import base64
def make_dir(path):
@@ -29,6 +30,20 @@ def read_json_file(json_file_name):
data = json.load(f)
return data
+# 自适配读取文件
+def read_file(file_path):
+ ext = file_path.split('.')[-1]
+ if ext in ['jpg', 'png']:
+ return read_img_file(file_path)
+ elif ext in ['txt']:
+ return read_txt_file(file_path)
+ return ''
+
+# 读取img文件
+def read_img_file(file_path):
+ with open(file_path, 'rb') as f:
+ data = f.read()
+ return base64.b64encode(data).decode("ascii")
# 读取txt文件
def read_txt_file(file_path):
diff --git a/fe/config/index.js b/fe/config/index.js
index 94ad609..ba981cb 100644
--- a/fe/config/index.js
+++ b/fe/config/index.js
@@ -12,8 +12,8 @@ module.exports = {
assetsPublicPath: '/',
proxyTable: {
'/v1/': {
- // target: 'http://localhost:9060/',
- target: 'https://tekii.cn/',
+ target: 'http://localhost:9060/',
+ // target: 'https://tekii.cn/',
}
},
diff --git a/fe/src/components/NER/index.vue b/fe/src/components/NER/index.vue
index 84cc68c..fe40ae9 100644
--- a/fe/src/components/NER/index.vue
+++ b/fe/src/components/NER/index.vue
@@ -106,6 +106,9 @@
+