abhisheksan commited on
Commit
fc6d16b
·
verified ·
1 Parent(s): bce493a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -65,7 +65,6 @@ async def get_analysis_service() -> AnalysisService:
65
  @app.on_event("startup")
66
  async def startup_event():
67
  """Initialize services on startup."""
68
- global app_ready
69
 
70
  logger.info("Starting up WesternFront API")
71
 
@@ -80,9 +79,7 @@ async def startup_event():
80
 
81
  # Set analysis service's twitter service reference
82
  analysis_service.twitter_service = twitter_service
83
-
84
- # Mark application as ready immediately after core services are initialized
85
- app_ready = True
86
  logger.info("Application ready to accept requests")
87
 
88
  # Only start background tasks if auto-update is enabled
@@ -95,7 +92,6 @@ async def startup_event():
95
 
96
  except Exception as e:
97
  logger.error(f"Error during startup: {e}")
98
- app_ready = False # Keep app in not-ready state if startup fails
99
 
100
 
101
  @app.on_event("shutdown")
@@ -163,7 +159,36 @@ async def scheduled_update_task() -> None:
163
  except Exception as e:
164
  logger.error(f"Error in scheduled_update_task: {str(e)}")
165
 
 
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  @app.get("/", response_model=Dict)
168
  async def root():
169
  """Root endpoint with basic information about the API."""
 
65
  @app.on_event("startup")
66
  async def startup_event():
67
  """Initialize services on startup."""
 
68
 
69
  logger.info("Starting up WesternFront API")
70
 
 
79
 
80
  # Set analysis service's twitter service reference
81
  analysis_service.twitter_service = twitter_service
82
+
 
 
83
  logger.info("Application ready to accept requests")
84
 
85
  # Only start background tasks if auto-update is enabled
 
92
 
93
  except Exception as e:
94
  logger.error(f"Error during startup: {e}")
 
95
 
96
 
97
  @app.on_event("shutdown")
 
159
  except Exception as e:
160
  logger.error(f"Error in scheduled_update_task: {str(e)}")
161
 
162
+ app_ready = True # Force this to True for Hugging Face Spaces
163
 
164
+ # Update the root endpoint to be Hugging Face Spaces friendly
165
+ @app.get("/", response_class=HTMLResponse)
166
+ async def root():
167
+ """Root endpoint designed for Hugging Face Spaces."""
168
+ html_content = """
169
+ <!DOCTYPE html>
170
+ <html>
171
+ <head>
172
+ <title>WesternFront API</title>
173
+ <meta property="og:title" content="WesternFront API">
174
+ <meta property="og:description" content="AI-powered conflict tracker for India-Pakistan tensions">
175
+ </head>
176
+ <body>
177
+ <h1>WesternFront API</h1>
178
+ <p>API is running successfully! Access the API documentation at <a href="/docs">/docs</a></p>
179
+ <p>Version: 1.1.0</p>
180
+ <p>Status: Ready</p>
181
+ </body>
182
+ </html>
183
+ """
184
+ return HTMLResponse(content=html_content)
185
+
186
+ # Add a Hugging Face Spaces specific health check endpoint
187
+ @app.get("/health-check")
188
+ async def hf_health_check():
189
+ """Health check endpoint specifically for Hugging Face Spaces."""
190
+ return JSONResponse(status_code=200, content={"status": "healthy"})
191
+
192
  @app.get("/", response_model=Dict)
193
  async def root():
194
  """Root endpoint with basic information about the API."""