krishnachoudhary-hclguvi commited on
Meet OpenEnv spec compliance: replace Gradio with FastAPI endpoints, add openenv.yaml
Browse files- Dockerfile +2 -2
- app.py +52 -24
- openenv.yaml +14 -0
- requirements.txt +4 -1
Dockerfile
CHANGED
|
@@ -25,5 +25,5 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 25 |
# Expose port 7860 (Hugging Face Spaces default)
|
| 26 |
EXPOSE 7860
|
| 27 |
|
| 28 |
-
# Command to run the
|
| 29 |
-
CMD ["
|
|
|
|
| 25 |
# Expose port 7860 (Hugging Face Spaces default)
|
| 26 |
EXPOSE 7860
|
| 27 |
|
| 28 |
+
# Command to run the FastAPI UI
|
| 29 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,27 +1,55 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
-
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Optional
|
| 4 |
+
from code_review_env import CodeReviewEnv
|
| 5 |
+
|
| 6 |
+
app = FastAPI(title="OpenEnv Code Review Space")
|
| 7 |
+
|
| 8 |
+
_env = None
|
| 9 |
+
|
| 10 |
+
class ActionRequest(BaseModel):
|
| 11 |
+
action: str
|
| 12 |
+
|
| 13 |
+
class ResetRequest(BaseModel):
|
| 14 |
+
difficulty: str = "medium"
|
| 15 |
+
|
| 16 |
+
@app.get("/")
|
| 17 |
+
def ping():
|
| 18 |
+
return {"status": "ok", "message": "Hugging Face Space is running"}
|
| 19 |
+
|
| 20 |
+
@app.post("/reset")
|
| 21 |
+
def reset(req: ResetRequest):
|
| 22 |
+
global _env
|
| 23 |
+
_env = CodeReviewEnv(difficulty=req.difficulty)
|
| 24 |
+
obs = _env.reset()
|
| 25 |
+
return {"observation": obs, "status": "reset_successful"}
|
| 26 |
+
|
| 27 |
+
@app.post("/step")
|
| 28 |
+
def step(req: ActionRequest):
|
| 29 |
+
global _env
|
| 30 |
+
if _env is None:
|
| 31 |
+
raise HTTPException(status_code=400, detail="Environment not initialized. Call /reset first.")
|
| 32 |
|
| 33 |
+
obs, reward, done, error = _env.step(req.action)
|
| 34 |
+
return {
|
| 35 |
+
"observation": obs,
|
| 36 |
+
"reward": float(reward) if reward else 0.0,
|
| 37 |
+
"done": done,
|
| 38 |
+
"error": error
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
@app.get("/state")
|
| 42 |
+
def state():
|
| 43 |
+
global _env
|
| 44 |
+
if _env is None:
|
| 45 |
+
return {"status": "uninitialized"}
|
| 46 |
+
return {
|
| 47 |
+
"steps_taken": _env.steps_taken,
|
| 48 |
+
"rewards": _env.rewards,
|
| 49 |
+
"difficulty": _env.difficulty,
|
| 50 |
+
"correct_comments": _env.correct_comments
|
| 51 |
+
}
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
import uvicorn
|
| 55 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|
openenv.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: code_review_env
|
| 2 |
+
version: "1.0.0"
|
| 3 |
+
description: "A Code Review environment that tests an agent's ability to locate bugs in code snippets."
|
| 4 |
+
tasks:
|
| 5 |
+
- id: code_review_task_easy
|
| 6 |
+
description: "Review simple code snippets under 10 lines."
|
| 7 |
+
- id: code_review_task_medium
|
| 8 |
+
description: "Review moderate code snippets between 10 and 30 lines."
|
| 9 |
+
- id: code_review_task_hard
|
| 10 |
+
description: "Review complex code snippets over 30 lines."
|
| 11 |
+
endpoints:
|
| 12 |
+
reset: "/reset"
|
| 13 |
+
step: "/step"
|
| 14 |
+
state: "/state"
|
requirements.txt
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
openai>=1.0.0
|
| 2 |
python-dotenv
|
| 3 |
datasets
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Add any required OpenEnv or domain-specific packages below:
|
| 7 |
# openenv
|
|
|
|
| 1 |
openai>=1.0.0
|
| 2 |
python-dotenv
|
| 3 |
datasets
|
| 4 |
+
fastapi
|
| 5 |
+
uvicorn
|
| 6 |
+
pydantic
|
| 7 |
+
|
| 8 |
|
| 9 |
# Add any required OpenEnv or domain-specific packages below:
|
| 10 |
# openenv
|