diff --git a/src/model_meta/app.py b/src/model_meta/app.py new file mode 100755 index 0000000..33ce16b --- /dev/null +++ b/src/model_meta/app.py @@ -0,0 +1,57 @@ +import os +import json + +from flask import Flask, request + + +model_task = os.getenv('TASK', '') +app = Flask(__name__) + +def get_task_input_examples(task): + current_work_dir = os.path.dirname(__file__) + with open(current_work_dir + '/data/data/pipeline_inputs.json', 'r') as f: + input_examples = json.load(f) + if task in input_examples: + return input_examples[task] + return None + + +@app.route('/schemas', methods=['GET']) +def get_schemas(): + request_id = request.headers.get("x-fc-request-id", "") + schemas_task = request.args.get("task", model_task) + + if not schemas_task: + err_ret = { + 'Code': 400, + 'Message': "failed", + 'Data': "param task is null", + "RequestId": request_id, + "Success": False + } + return err_ret, 400, [("x-fc-status", "400")] + + print("[INFO] get schemas by task: " + schemas_task) + result = get_task_input_examples(schemas_task) + if not result: + err_ret = { + 'Code': 400, + 'Message': "failed", + 'Data': "param task is invalid.", + "RequestId": request_id, + "Success": False + } + return err_ret, 400, [("x-fc-status", "400")] + + return { + 'Code': 200, + 'Message': "", + 'Data': result, + "RequestId": request_id, + "Success": True + }, 200, [("Content-Type", "application/json")] + + +if __name__ == '__main__': + os.system('mkdir data; cd data; wget https://modelscope.oss-cn-beijing.aliyuncs.com/swingdeploy/deploy.tar; tar xvf deploy.tar') + app.run(debug=False, host='0.0.0.0', port=9000) diff --git a/src/s.yaml b/src/s.yaml index 6b4caf4..0401493 100644 --- a/src/s.yaml +++ b/src/s.yaml @@ -82,17 +82,23 @@ resources: memorySize: 32768 cpu: 8 diskSize: 512 - gpuConfig: - gpuMemorySize: 16384 - gpuType: fc.gpu.tesla.1 instanceConcurrency: 1 - runtime: custom-container + runtime: python3.9 + code: ./model_meta internetAccess: true - customContainerConfig: - image: registry.${vars.region}.aliyuncs.com/modelscope-repo/modelscope:${vars.version} - port: 9000 + initializer: 'true' environmentVariables: - MODELSCOPE_CACHE: ${resources.model_cache.output.nasConfig.mountPoints.0.mountDir} + MODEL_ID: ${vars.modelID} + MODEL_VERSION: ${vars.modelRevision} + TASK: ${vars.modelTask} + PATH: /opt/python3.9/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin + PYTHONPATH: /opt/python + customRuntimeConfig: + command: + - python3.9 + args: + - "app.py" + port: 9000 triggers: - triggerName: httpTrigger triggerType: http