Spaces:
Sleeping
Sleeping
Download server/app.py from farishkhaan/code-review: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/farishkhaan/code-review/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/farishkhaan/code-review/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/farishkhaan/code-review/resolve/main/server/app.py
1.67 kB
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import sys | |
| import os | |
| # Add parent directory to path to import environment and models | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from environment import CodeReviewEnv | |
| from models import CodeReviewAction | |
| app = FastAPI() | |
| class ResetRequest(BaseModel): | |
| task_id: str = "easy_classify" | |
| # Initialize the environment (defaults to easy task) | |
| env = CodeReviewEnv() | |
| def health_check(): | |
| """Health check endpoint for Dockerfile HEALTHCHECK and HF Spaces ping [cite: 13, 200]""" | |
| return {"status": "ok", "message": "Code Review Environment is live"} | |
| def reset_env(req: ResetRequest = None): | |
| """The automated reset check [cite: 34, 46]""" | |
| task_id = req.task_id if req else "easy_classify" | |
| obs = env.reset(task_id=task_id) | |
| return {"observation": obs.model_dump()} | |
| def get_state(): | |
| """Returns current environment state [cite: 36, 46]""" | |
| return env.state.model_dump() | |
| def step_env(action: CodeReviewAction): | |
| """The automated step execution [cite: 34, 46]""" | |
| # Matches your template: obs, reward, done, info | |
| obs = env.step(action) | |
| return { | |
| "observation": obs.model_dump(), | |
| "reward": obs.reward, # Using the reward field from the Observation [cite: 23, 25] | |
| "done": obs.done | |
| } | |
| # --- MANDATORY ENTRY POINT FOR THE GRADER --- | |
| # Required for docker and local execution [cite: 201, 253] | |
| def main(): | |
| import uvicorn | |
| uvicorn.run("server.app:app", host="0.0.0.0", port=7860) | |
| if __name__ == "__main__": | |
| main() |