summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhaoyh6 <zhaoyh6@asiainfo.com>2021-09-23 11:06:57 +0800
committerzhaoyh6 <zhaoyh6@asiainfo.com>2021-09-23 11:07:08 +0800
commit698bd185b568e159999649b8270166feb47fcb43 (patch)
tree416dd1ac4f42c7b4fd001d731c05be488f02ba50
parent280d97f0572158e1520d6c5ae3ce2fe2afe8b70d (diff)
feat:Add file transfer functionistanbul
Issue-ID: USECASEUI-605 Signed-off-by: zhaoyh6 <zhaoyh6@asiainfo.com> Change-Id: Ic5429e61c394e2a430fdc5ffc75b2b5fb4744bed
-rw-r--r--nlp/scripts/upload.py51
-rwxr-xr-xstandalone/src/main/assembly/run.sh1
2 files changed, 52 insertions, 0 deletions
diff --git a/nlp/scripts/upload.py b/nlp/scripts/upload.py
new file mode 100644
index 0000000..abc5610
--- /dev/null
+++ b/nlp/scripts/upload.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+# auther = 'zhaoyehua'
+# date = 20210918
+
+
+from flask import Flask, request, render_template
+import zipfile
+import shutil
+import os
+
+app = Flask(__name__)
+app.config['UPLOAD_FOLDER'] = 'upload/'
+
+@app.route("/uploader", methods=["POST"])
+def uploader():
+ print("aa")
+ if request.method == 'POST':
+ f = request.files['file']
+ print(f.filename)
+ f.save(os.path.join(app.config['UPLOAD_FOLDER'], f.filename))
+ return "ok"
+
+@app.route("/unzipFile/<fileName>", methods=["GET"])
+def unzipFile(fileName):
+ zip_file = zipfile.ZipFile(os.path.join(app.config['UPLOAD_FOLDER'], fileName))
+ parentDir = os.path.join(app.config['UPLOAD_FOLDER'], fileName.split(".zip")[0])
+ if os.path.isdir(parentDir):
+ pass
+ else:
+ os.mkdir(parentDir)
+ for names in zip_file.namelist():
+ zip_file.extract(names, parentDir)
+ zip_file.close()
+ return parentDir
+
+@app.route("/deleteFile/<fileName>", methods=["GET"])
+def deleteFile(fileName):
+ path = os.path.join(app.config['UPLOAD_FOLDER'], fileName)
+ if os.path.exists(path):
+ os.remove(path)
+ dirPath = path.split(".zip")[0]
+ if os.path.isdir(dirPath):
+ shutil.rmtree(dirPath)
+ return "ok"
+ return "ok"
+ return "error: no such file"
+
+if __name__ == '__main__':
+ app.run(host="0.0.0.0", port=33013) \ No newline at end of file
diff --git a/standalone/src/main/assembly/run.sh b/standalone/src/main/assembly/run.sh
index ec7fc66..6ec5f75 100755
--- a/standalone/src/main/assembly/run.sh
+++ b/standalone/src/main/assembly/run.sh
@@ -27,5 +27,6 @@ cd /home/run/bert-master/
nohup python -u api_squad_online.py 33011 > online.log 2>&1 &
nohup python -u api_squad_offline.py 33012 > offline.log 2>&1 &
+nohup python -u upload.py 33013 > upload.log 2>&1 &
/usr/bin/tf_serving_entrypoint.sh