krishnachoudhary-hclguvi commited on
Commit
f59a9d8
·
unverified ·
1 Parent(s): 1d48da1

Meet OpenEnv spec compliance: replace Gradio with FastAPI endpoints, add openenv.yaml

Browse files
Files changed (4) hide show
  1. Dockerfile +2 -2
  2. app.py +52 -24
  3. openenv.yaml +14 -0
  4. 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 Gradio UI
29
- CMD ["python", "app.py"]
 
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
- import gradio as gr
2
- import subprocess
3
-
4
- def run_inference():
5
- try:
6
- # Run inference.py and capture exact output
7
- result = subprocess.run(['python', 'inference.py'], capture_output=True, text=True, timeout=30)
8
- return result.stdout + "\n" + result.stderr
9
- except subprocess.TimeoutExpired:
10
- return "Process timed out after 30 seconds."
11
- except Exception as e:
12
- return str(e)
13
-
14
- with gr.Blocks(title="OpenEnv Code Review Hackathon", theme=gr.themes.Soft()) as app:
15
- gr.Markdown("# OpenEnv Environment: Code Review")
16
- gr.Markdown("This interface runs the `inference.py` backend and displays the `[START]`, `[STEP]`, `[END]` output strictly required by the hackathon spec.")
17
-
18
- with gr.Row():
19
- run_btn = gr.Button("Run Inference Agent")
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- with gr.Row():
22
- output_display = gr.Textbox(label="Agent Output Log", lines=15, interactive=False)
23
-
24
- run_btn.click(fn=run_inference, outputs=output_display)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  if __name__ == "__main__":
27
- app.launch(server_name="0.0.0.0", server_port=7860)
 
 
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
- gradio
 
 
 
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