LogicGoInfotechSpaces commited on
Commit
763e798
·
verified ·
1 Parent(s): 6a19dff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -49
app.py CHANGED
@@ -929,62 +929,62 @@ DEFAULT_WITH_MODEL_NAME = True
929
  # Singleton Upscale instance for API
930
  _api_upscale = Upscale()
931
 
932
- # @fastapi_app.get("/health")
933
- # def health(_: bool = Depends(_verify_bearer_token)):
934
- # return {"status": "ok"}
935
  @fastapi_app.get("/health")
936
- async def health(_: bool = Depends(_verify_bearer_token)):
937
- checks = {
938
- "api": "ok",
939
- "gpu": "unknown",
940
- "torch": "unknown",
941
- "disk": "unknown",
942
- "mongo": "skipped",
943
- "weights_dir": "unknown",
944
- "timestamp": datetime.utcnow().isoformat()
945
- }
 
 
 
946
 
947
- errors = {}
948
 
949
- # -------- 1. TORCH & CUDA CHECK --------
950
- try:
951
- checks["torch"] = torch.__version__
952
- checks["gpu"] = "available" if torch.cuda.is_available() else "cpu-only"
953
- if torch.cuda.is_available():
954
- checks["gpu_name"] = torch.cuda.get_device_name(0)
955
- checks["gpu_mem_allocated_mb"] = int(torch.cuda.memory_allocated(0) / 1024 / 1024)
956
- except Exception as e:
957
- checks["gpu"] = "failed"
958
- errors["gpu"] = str(e)
959
- # -------- 2. MONGODB CHECK (OPTIONAL) --------
960
- if _mongo_client is not None:
961
- try:
962
- def mongo_ping():
963
- _mongo_client.admin.command("ping")
964
 
965
- await run_in_threadpool(mongo_ping)
966
- checks["mongo"] = "connected"
967
- except Exception as e:
968
- checks["mongo"] = "failed"
969
- errors["mongo"] = str(e)
970
- else:
971
- checks["mongo"] = "not_configured"
972
 
973
- # -------- FINAL STATUS --------
974
- is_healthy = len(errors) == 0
975
 
976
- if is_healthy:
977
- checks["status"] = "healthy"
978
- return checks
979
 
980
- raise HTTPException(
981
- status_code=503,
982
- detail={
983
- "status": "unhealthy",
984
- "checks": checks,
985
- "errors": errors
986
- }
987
- )
988
  @fastapi_app.get("/source")
989
  def source(_: bool = Depends(_verify_bearer_token)):
990
  return {
 
929
  # Singleton Upscale instance for API
930
  _api_upscale = Upscale()
931
 
 
 
 
932
  @fastapi_app.get("/health")
933
+ def health(_: bool = Depends(_verify_bearer_token)):
934
+ return {"status": "ok"}
935
+ # @fastapi_app.get("/health")
936
+ # async def health(_: bool = Depends(_verify_bearer_token)):
937
+ # checks = {
938
+ # "api": "ok",
939
+ # "gpu": "unknown",
940
+ # "torch": "unknown",
941
+ # "disk": "unknown",
942
+ # "mongo": "skipped",
943
+ # "weights_dir": "unknown",
944
+ # "timestamp": datetime.utcnow().isoformat()
945
+ # }
946
 
947
+ # errors = {}
948
 
949
+ # # -------- 1. TORCH & CUDA CHECK --------
950
+ # try:
951
+ # checks["torch"] = torch.__version__
952
+ # checks["gpu"] = "available" if torch.cuda.is_available() else "cpu-only"
953
+ # if torch.cuda.is_available():
954
+ # checks["gpu_name"] = torch.cuda.get_device_name(0)
955
+ # checks["gpu_mem_allocated_mb"] = int(torch.cuda.memory_allocated(0) / 1024 / 1024)
956
+ # except Exception as e:
957
+ # checks["gpu"] = "failed"
958
+ # errors["gpu"] = str(e)
959
+ # # -------- 2. MONGODB CHECK (OPTIONAL) --------
960
+ # if _mongo_client is not None:
961
+ # try:
962
+ # def mongo_ping():
963
+ # _mongo_client.admin.command("ping")
964
 
965
+ # await run_in_threadpool(mongo_ping)
966
+ # checks["mongo"] = "connected"
967
+ # except Exception as e:
968
+ # checks["mongo"] = "failed"
969
+ # errors["mongo"] = str(e)
970
+ # else:
971
+ # checks["mongo"] = "not_configured"
972
 
973
+ # # -------- FINAL STATUS --------
974
+ # is_healthy = len(errors) == 0
975
 
976
+ # if is_healthy:
977
+ # checks["status"] = "healthy"
978
+ # return checks
979
 
980
+ # raise HTTPException(
981
+ # status_code=503,
982
+ # detail={
983
+ # "status": "unhealthy",
984
+ # "checks": checks,
985
+ # "errors": errors
986
+ # }
987
+ # )
988
  @fastapi_app.get("/source")
989
  def source(_: bool = Depends(_verify_bearer_token)):
990
  return {