diff --git a/deploy/Dockerfile b/deploy/Dockerfile
index af4b2f4..4812ae7 100644
--- a/deploy/Dockerfile
+++ b/deploy/Dockerfile
@@ -1,10 +1,13 @@
FROM ubuntu:20.04
-RUN mkdir /work
-COPY ../eval /work
-WORKDIR /work
+COPY ./ /work
+RUN mkdir -p /work/results
+WORKDIR /work/eval
RUN apt-get update && apt-get install -y python3 python3-pip python3-dev gcc g++ libffi-dev libssl-dev
RUN pip install cython
RUN pip install cryptography
-RUN pip install -r requirements.txt
+RUN pip install gunicorn
+RUN pip install -r /work/deploy/requirements.txt
-ENTRYPOINT ["gunicorn", "--workers=4", "--bind=0.0.0.0:5000", "deploy:app"]
\ No newline at end of file
+EXPOSE 5000
+
+ENTRYPOINT ["gunicorn", "--workers=4", "--log-level", "debug", "--bind=0.0.0.0:5000", "deploy:app"]
\ No newline at end of file
diff --git a/deploy/Makefile b/deploy/Makefile
new file mode 100644
index 0000000..e248d7a
--- /dev/null
+++ b/deploy/Makefile
@@ -0,0 +1,7 @@
+mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
+cur_makefile_path := $(dir $(mkfile_path))
+build:
+ docker build $(cur_makefile_path)\.. -f $(cur_makefile_path)\Dockerfile -t multi-benchmark --progress=plain
+
+run:
+ docker run --name multi-benchmark_test -p 5000:5000 -v $(cur_makefile_path)/../data:/work/data -d multi-benchmark
\ No newline at end of file
diff --git a/deploy/requirements.txt b/deploy/requirements.txt
index bdc28c3..3c5d998 100644
Binary files a/deploy/requirements.txt and b/deploy/requirements.txt differ
diff --git a/deploy/test.html b/deploy/test.html
new file mode 100644
index 0000000..97e2f58
--- /dev/null
+++ b/deploy/test.html
@@ -0,0 +1,66 @@
+
+
+
+
+
+Fetch File Example
+
+
+Upload and Send File Example
+
+
+
+
+
+
+
diff --git a/eval/args.py b/eval/args.py
index c321d05..f1856c9 100644
--- a/eval/args.py
+++ b/eval/args.py
@@ -162,23 +162,24 @@ def parse_args_for_score():
return args
def parse_args_for_score_deploy():
- parser = argparse.ArgumentParser()
+ class Args:
+ pass
# data setting
- parser.add_argument('--label_file', type=str, default=None, help='Specify the label json file.')
- parser.add_argument('--prediction_dir', type=str, default=None, help='Specify the prediction json files dir.')
- parser.add_argument('--prediction_file', type=str, default=None, help='Specify the prediction json file.')
- parser.add_argument('--score_file', type=str, default=None, help='Specify the output detail score file.')
- parser.add_argument('--reference_dir', type=str, default=None, help='Specify the reference directory where all the other score files are stored. By leaving it empty, only absolute score will be calculated.')
-
+ args = Args()
+ args.label_file = None
+ args.prediction_dir = None
+ args.prediction_file = None
+ args.score_file = None
+ args.reference_dir = None
+
# score setting
- parser.add_argument('--detail', action='store_true', help='Whether to print the detail of the score.')
- parser.add_argument('--only_past', action='store_true', help='Whether to only use the earlier models to calculate the relative score.')
-
+ args.detail = False
+ args.only_past = False
+
# other functions
- parser.add_argument('--model_list', '-l', action='store_true', help='Print the available model list.')
-
- args = parser.parse_args()
+ args.model_list = False
+
return args
diff --git a/eval/deploy.py b/eval/deploy.py
index 606a8d0..ad2097b 100644
--- a/eval/deploy.py
+++ b/eval/deploy.py
@@ -3,30 +3,50 @@
import uuid
from metrics import *
from args import parse_args_for_score_deploy
-
-from flask import Flask, request, jsonify
-
-
+from flask import Flask, request, jsonify, send_file
+from flask_cors import CORS
+import io
+from contextlib import redirect_stdout
+import zipfile
+
+# redirect stdout to string
+output = io.StringIO()
app = Flask(__name__)
+CORS(app)
+
args = parse_args_for_score_deploy()
+# args.label_file = "../data/problem_v1.2.2_20240212.json"
+args.label_file = "../data/problem_final.json"
+args.detail = True
+args.prediction_dir = "../results"
+source_suffix = "/source"
+prediction_file_suffix = "/prediction.json"
+paras_file_suffix = "/paras.json"
+result_zip_suffix = "/result.zip"
-prediction_file_suffix = "/prediction.json"
-result_file_suffix = "/result.json"
+def get_random_dir():
+ return os.path.join(args.prediction_dir, str(uuid.uuid4()))
-def save_prediction_json_to_random_dir(json_data):
- random_dir = os.path.join(args.prediction_dir, str(uuid.uuid4()))
- os.makedirs(random_dir)
- with open(random_dir + prediction_file_suffix, "w") as f:
+def save_prediction_json_to_target_dir(json_data, target_dir):
+ os.makedirs(target_dir)
+ with open(target_dir + prediction_file_suffix, "w") as f:
json.dump(json_data, f)
- return random_dir
-def save_result_to_target_dir(result, target_dir):
- with open(target_dir + result_file_suffix, "w") as f:
- json.dump(result, f)
+def save_paras_to_target_dir(paras_data, target_dir):
+ with open(target_dir + paras_file_suffix, "w") as f:
+ json.dump(paras_data, f)
+
+
+def zip_dir(directory, zip_filename):
+ with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
+ for root, _, files in os.walk(directory):
+ for file in files:
+ file_path = os.path.join(root, file)
+ zipf.write(file_path, os.path.relpath(file_path, directory))
# generate all
@@ -34,16 +54,36 @@ def save_result_to_target_dir(result, target_dir):
@app.route("/generate", methods=["POST"])
def generate():
- prediction_json = request.json["prediction_json"]
+ prediction_json = request.json.get("prediction_json", None)
if prediction_json is None:
return jsonify({"result": "false"})
- prediction_file = save_prediction_json_to_random_dir(prediction_json)
- result_json = request.json
- save_result_to_target_dir(result_json, prediction_file)
+
+ # generate random dir
+ random_dir = get_random_dir()
+ source_dir = random_dir + source_suffix
+
+ # save prediction json to random dir
+ save_prediction_json_to_target_dir(json.loads(
+ prediction_json["fileContent"]), source_dir)
+ prediction_file = source_dir + prediction_file_suffix
+
+ # save request json too
+ paras_json = request.json
+ save_paras_to_target_dir(paras_json, source_dir)
+
+ # change the args
copy_args = copy.deepcopy(args)
copy_args.prediction_file = prediction_file
- main(copy_args)
- return jsonify({"result": "true"})
+
+ # run the main function
+ with redirect_stdout(output):
+ main(copy_args)
+ app.logger.info(output.getvalue())
+
+ # zip the dir
+ zip_dir(source_dir, random_dir + result_zip_suffix)
+
+ return send_file(random_dir + result_zip_suffix, as_attachment=True)
if __name__ == "__main__":