LogicGoInfotechSpaces commited on
Commit
972563b
·
verified ·
1 Parent(s): 375118a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -70
app.py CHANGED
@@ -94,77 +94,12 @@ class HealthResponse(BaseModel):
94
  # ---------------------------------------------------------------------
95
  # Endpoints
96
  # ---------------------------------------------------------------------
97
- # @app.get("/health", response_model=HealthResponse)
98
- # def health():
99
- # """Public health check"""
100
- # mongo.admin.command("ping")
101
- # return HealthResponse(status="ok", db=db.name, model="Qwen/Qwen-Image-Edit")
102
- @app.get("/health")
103
- async def health():
104
- checks = {
105
- "api": "ok",
106
- "mongo": "unknown",
107
- "gridfs": "unknown",
108
- "firebase": "unknown",
109
- "huggingface": "unknown",
110
- "timestamp": datetime.utcnow().isoformat()
111
- }
112
-
113
- errors = {}
114
-
115
- # ------------------ MONGO CHECK ------------------
116
- try:
117
- def mongo_ping():
118
- mongo.admin.command("ping")
119
-
120
- await run_in_threadpool(mongo_ping)
121
- checks["mongo"] = "connected"
122
- except Exception as e:
123
- checks["mongo"] = "failed"
124
- errors["mongo"] = str(e)
125
-
126
- # ------------------ GRIDFS CHECK ------------------
127
- try:
128
- def gridfs_test():
129
- test_id = fs.put(b"healthcheck", filename="health.txt")
130
- fs.delete(test_id)
131
-
132
- await run_in_threadpool(gridfs_test)
133
- checks["gridfs"] = "ok"
134
- except Exception as e:
135
- checks["gridfs"] = "failed"
136
- errors["gridfs"] = str(e)
137
 
138
- # ------------------ FIREBASE CHECK ------------------
139
- try:
140
- _ = firebase_admin.get_app()
141
- checks["firebase"] = "initialized"
142
- except Exception as e:
143
- checks["firebase"] = "failed"
144
- errors["firebase"] = str(e)
145
-
146
- # ------------------ HUGGINGFACE CHECK ------------------
147
- try:
148
- _ = hf_client.model_info("Qwen/Qwen-Image-Edit")
149
- checks["huggingface"] = "reachable"
150
- except Exception as e:
151
- checks["huggingface"] = "failed"
152
- errors["huggingface"] = str(e)
153
- # ------------------ FINAL STATUS ------------------
154
- is_healthy = len(errors) == 0
155
-
156
- if is_healthy:
157
- checks["status"] = "healthy"
158
- return checks
159
-
160
- raise HTTPException(
161
- status_code=503,
162
- detail={
163
- "status": "unhealthy",
164
- "checks": checks,
165
- "errors": errors
166
- }
167
- )
168
 
169
  @app.post("/generate")
170
  async def generate(
 
94
  # ---------------------------------------------------------------------
95
  # Endpoints
96
  # ---------------------------------------------------------------------
97
+ @app.get("/health", response_model=HealthResponse)
98
+ def health():
99
+ """Public health check"""
100
+ mongo.admin.command("ping")
101
+ return HealthResponse(status="ok", db=db.name, model="Qwen/Qwen-Image-Edit")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  @app.post("/generate")
105
  async def generate(