You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 1.4 kB

2 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import argparse
  2. import uvicorn
  3. from fastapi import FastAPI, File, UploadFile
  4. from fastapi.responses import Response, JSONResponse
  5. import os
  6. from c2net.context import prepare
  7. import os
  8. c2net_context = prepare()
  9. files = [f for f in os.listdir(c2net_context.pretrain_model_path) if os.path.isdir(c2net_context.pretrain_model_path+ f"/{f}")]
  10. model_name = ""
  11. for file in files:
  12. if (not file.startswith(".")) and len(os.listdir(c2net_context.pretrain_model_path+ f"/{file}")) > 0:
  13. model_name = file
  14. break
  15. model_path = c2net_context.pretrain_model_path + f"/{model_name}"
  16. pth_file = ""
  17. for root, dirs, files in os.walk(model_path):
  18. for file in files:
  19. if file.endswith(".pth"):
  20. pth_file = file
  21. parser = argparse.ArgumentParser(description='忽略超参数不存在的报错问题')
  22. # #添加自定义参数
  23. parser.add_argument("--output")
  24. args = parser.parse_args()
  25. args, unknown = parser.parse_known_args()
  26. TIMEOUT_KEEP_ALIVE = 20
  27. base_url = os.getenv('OPENI_SELF_URL')
  28. app = FastAPI()
  29. @app.get(os.path.join(base_url,"test"))
  30. async def api_get():
  31. return model_name + "|" + model_path + "|" + pth_file
  32. if __name__ == '__main__':
  33. print("this is a test")
  34. print(args)
  35. print(unknown)
  36. print(args.output)
  37. uvicorn.run(app, host='0.0.0.0', port=int(os.getenv('OPENI_SELF_PORT')), timeout_keep_alive=TIMEOUT_KEEP_ALIVE)

No Description