aastikny commited on
Commit
783acf6
·
verified ·
1 Parent(s): 59b106e

Update server/app.py

Browse files
Files changed (1) hide show
  1. server/app.py +8 -8
server/app.py CHANGED
@@ -3,28 +3,28 @@ from fastapi import FastAPI
3
  import sys
4
  import os
5
 
6
- # Ensure the root directory is in the path so we can import env.py
7
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 
 
 
8
  from env import DatabaseRescueEnv
9
 
10
- # OpenEnv looks for an ASGI 'app' object
11
  app = FastAPI(title="SQLite Rescue Environment API")
12
  env_instance = DatabaseRescueEnv()
13
 
14
  @app.get("/")
15
  def health_check():
16
- """Satisfies the HF Space health check ping (must return 200)."""
17
  return {"status": "ok", "environment": "sqlite-rescue-env"}
18
 
19
  @app.post("/reset")
20
  def reset_env(task_name: str = "easy_data_cleaning"):
21
- """Satisfies the pre-submission HF Space ping for reset()."""
22
  obs = env_instance.reset(task_name)
23
- return {"status": "reset", "observation": obs.dict()}
24
 
25
  def main():
26
- """The entry point referenced in pyproject.toml."""
27
- uvicorn.run("server.app:app", host="0.0.0.0", port=8000)
28
 
29
  if __name__ == "__main__":
30
  main()
 
3
  import sys
4
  import os
5
 
6
+ # Force the root directory into the python path
7
+ current_dir = os.path.dirname(os.path.abspath(__file__))
8
+ parent_dir = os.path.dirname(current_dir)
9
+ if parent_dir not in sys.path:
10
+ sys.path.insert(0, parent_dir)
11
+
12
  from env import DatabaseRescueEnv
13
 
 
14
  app = FastAPI(title="SQLite Rescue Environment API")
15
  env_instance = DatabaseRescueEnv()
16
 
17
  @app.get("/")
18
  def health_check():
 
19
  return {"status": "ok", "environment": "sqlite-rescue-env"}
20
 
21
  @app.post("/reset")
22
  def reset_env(task_name: str = "easy_data_cleaning"):
 
23
  obs = env_instance.reset(task_name)
24
+ return {"status": "reset", "observation": obs.model_dump()} # Changed .dict() to .model_dump() for Pydantic v2
25
 
26
  def main():
27
+ uvicorn.run(app, host="0.0.0.0", port=7860) # Port 7860 is the HF default
 
28
 
29
  if __name__ == "__main__":
30
  main()