Jofthomas commited on
Commit
5b9a69f
·
verified ·
1 Parent(s): d325870

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -0
main.py CHANGED
@@ -108,6 +108,21 @@ app = FastAPI(
108
  description="API to fetch questions and submit agent answers for scoring.",
109
  )
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  # --- Helper Function to interact with HF Dataset ---
112
  def update_huggingface_dataset(username: str, score: float):
113
  """Loads the dataset, updates the score if higher, and pushes back."""
 
108
  description="API to fetch questions and submit agent answers for scoring.",
109
  )
110
 
111
+ # --- Startup Event Handler ---
112
+ @app.on_event("startup")
113
+ async def startup_event():
114
+ """
115
+ Loads the questions when the FastAPI application starts.
116
+ """
117
+ logger.info("Application startup: Loading questions...")
118
+ load_questions() # Call your loading function here
119
+ if not questions_for_api:
120
+ logger.error("CRITICAL: No questions were loaded during startup. The /questions endpoint will fail.")
121
+ # Depending on requirements, you might want the app to fail startup
122
+ # raise RuntimeError("Failed to load mandatory question data.")
123
+ else:
124
+ logger.info(f"Successfully loaded {len(questions_for_api)} questions.")
125
+
126
  # --- Helper Function to interact with HF Dataset ---
127
  def update_huggingface_dataset(username: str, score: float):
128
  """Loads the dataset, updates the score if higher, and pushes back."""