|
- import argparse
- import uvicorn
- from fastapi import FastAPI, File, UploadFile
- from fastapi.responses import Response, JSONResponse
- import os
-
- from c2net.context import prepare
- import os
- c2net_context = prepare()
-
- files = [f for f in os.listdir(c2net_context.pretrain_model_path) if os.path.isdir(c2net_context.pretrain_model_path+ f"/{f}")]
- model_name = ""
-
- for file in files:
- if (not file.startswith(".")) and len(os.listdir(c2net_context.pretrain_model_path+ f"/{file}")) > 0:
- model_name = file
- break
-
- model_path = c2net_context.pretrain_model_path + f"/{model_name}"
-
- pth_file = ""
- for root, dirs, files in os.walk(model_path):
- for file in files:
- if file.endswith(".pth"):
- pth_file = file
-
- parser = argparse.ArgumentParser(description='忽略超参数不存在的报错问题')
- # #添加自定义参数
- parser.add_argument("--output")
-
- args = parser.parse_args()
- args, unknown = parser.parse_known_args()
-
- TIMEOUT_KEEP_ALIVE = 20
- base_url = os.getenv('OPENI_SELF_URL')
-
- app = FastAPI()
-
- @app.get(os.path.join(base_url,"test"))
- async def api_get():
- return model_name + "|" + model_path + "|" + pth_file
-
- if __name__ == '__main__':
- print("this is a test")
- print(args)
- print(unknown)
- print(args.output)
-
- uvicorn.run(app, host='0.0.0.0', port=int(os.getenv('OPENI_SELF_PORT')), timeout_keep_alive=TIMEOUT_KEEP_ALIVE)
|