aastikny commited on
Commit
6f8f2a4
·
verified ·
1 Parent(s): 1b629b2

Create server/app.py

Browse files
Files changed (1) hide show
  1. server/app.py +30 -0
server/app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uvicorn
2
+ 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()