Skip to content

Commit

Permalink
refine model_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
suluyana committed Sep 5, 2024
1 parent 11ded0c commit 6b3ec9a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
57 changes: 57 additions & 0 deletions src/model_meta/app.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 14 additions & 8 deletions src/s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b3ec9a

Please sign in to comment.