aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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