Afifa Kureshi commited on
Commit
8c16d43
·
1 Parent(s): 2f71013

Fix Docker

Browse files
Files changed (4) hide show
  1. Dockerfile +7 -3
  2. inference.py +0 -6
  3. requirements.txt +6 -1
  4. server.py +18 -0
Dockerfile CHANGED
@@ -2,11 +2,15 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
 
 
 
5
  COPY requirements.txt .
6
 
7
- RUN pip install --no-cache-dir -r requirements.txt
 
8
 
9
  COPY . .
10
 
11
- # Run inference script as main process
12
- CMD ["python", "inference.py"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Force Python to print logs immediately (Fixes the missing logs issue!)
6
+ ENV PYTHONUNBUFFERED=1
7
+
8
  COPY requirements.txt .
9
 
10
+ # Add fastapi and uvicorn to your requirements during the build
11
+ RUN pip install --no-cache-dir -r requirements.txt fastapi uvicorn
12
 
13
  COPY . .
14
 
15
+ # Start the web server on Port 7860 so Hugging Face can see it
16
+ CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
inference.py CHANGED
@@ -95,9 +95,3 @@ finally:
95
  f"score={score:.2f} "
96
  f"rewards={rewards_str}"
97
  )
98
-
99
- # Keep container alive (required for Hugging Face Spaces)
100
- import time
101
-
102
- while True:
103
- time.sleep(60)
 
95
  f"score={score:.2f} "
96
  f"rewards={rewards_str}"
97
  )
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,2 +1,7 @@
1
  pyyaml
2
- openenv-core
 
 
 
 
 
 
1
  pyyaml
2
+ openenv-core
3
+ fastapi==0.110.1
4
+ uvicorn==0.29.0
5
+
6
+ # Data Validation (Required for OpenEnv typed models)
7
+ pydantic==2.6.4
server.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from environment.cloud_env import CloudDataJanitorEnv
3
+ import uvicorn
4
+
5
+ app = FastAPI()
6
+ env = CloudDataJanitorEnv(task_name="easy")
7
+
8
+ @app.get("/")
9
+ def read_root():
10
+ # This is the endpoint Hugging Face pings to check if you are alive!
11
+ return {"status": "ok", "message": "Cloud Data Janitor is running"}
12
+
13
+ @app.post("/reset")
14
+ def reset_env():
15
+ state = env.reset()
16
+ return {"status": "ok", "state": state}
17
+
18
+ # You will also need to add endpoints for /step and /state based on your Pydantic models