kush5699 commited on
Commit
6b66cfc
·
verified ·
1 Parent(s): 65bcfd7

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. Dockerfile +1 -1
  2. openenv.yaml +2 -2
  3. pyproject.toml +3 -0
  4. server/__init__.py +1 -0
  5. server/app.py +154 -0
  6. uv.lock +0 -0
Dockerfile CHANGED
@@ -14,4 +14,4 @@ EXPOSE 8000
14
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
15
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
16
 
17
- CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8000"]
 
14
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
15
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
16
 
17
+ CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "8000"]
openenv.yaml CHANGED
@@ -2,9 +2,9 @@ spec_version: 1
2
  name: data_validation_env
3
  type: space
4
  runtime: fastapi
5
- app: server:app
6
  port: 8000
7
- description: "An RL environment for training agents to clean and validate structured data. The agent fixes missing values, type mismatches, format violations, range errors, and duplicates in datasets."
8
  version: "1.0.0"
9
  author: "kush3"
10
  tags:
 
2
  name: data_validation_env
3
  type: space
4
  runtime: fastapi
5
+ app: server.app:app
6
  port: 8000
7
+ description: "An RL environment for training agents to clean and validate structured data."
8
  version: "1.0.0"
9
  author: "kush3"
10
  tags:
pyproject.toml CHANGED
@@ -15,3 +15,6 @@ dependencies = [
15
  inference = [
16
  "openai>=1.0.0",
17
  ]
 
 
 
 
15
  inference = [
16
  "openai>=1.0.0",
17
  ]
18
+
19
+ [project.scripts]
20
+ server = "server.app:main"
server/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from server.app import app
server/app.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import traceback
3
+ from typing import Optional
4
+
5
+ from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect
6
+ from pydantic import BaseModel
7
+
8
+ from env.environment import DataValidationEnvironment
9
+ from env.models import DataCleanAction
10
+ from env.tasks import get_task_names
11
+
12
+ app = FastAPI(
13
+ title="Data Validation Pipeline - OpenEnv Environment",
14
+ version="1.0.0",
15
+ )
16
+
17
+ env = DataValidationEnvironment()
18
+
19
+
20
+ class ResetRequest(BaseModel):
21
+ task_name: Optional[str] = None
22
+ seed: int = 42
23
+
24
+
25
+ class StepRequest(BaseModel):
26
+ action_type: str
27
+ target_field: str = ""
28
+ target_row: int = 0
29
+ new_value: str = ""
30
+
31
+
32
+ @app.get("/")
33
+ async def root():
34
+ return {
35
+ "name": "Data Validation Pipeline",
36
+ "description": "An RL environment for training agents to clean and validate structured data",
37
+ "version": "1.0.0",
38
+ "endpoints": {
39
+ "health": "/health",
40
+ "reset": "POST /reset",
41
+ "step": "POST /step",
42
+ "state": "GET /state",
43
+ "tasks": "GET /tasks",
44
+ },
45
+ "tasks": get_task_names(),
46
+ "status": "running",
47
+ }
48
+
49
+
50
+ @app.get("/health")
51
+ async def health():
52
+ return {"status": "healthy", "service": "data-validation-env"}
53
+
54
+
55
+ @app.post("/reset")
56
+ async def reset(request: ResetRequest = None):
57
+ if request is None:
58
+ request = ResetRequest()
59
+ try:
60
+ obs = env.reset(task_name=request.task_name, seed=request.seed)
61
+ return obs.model_dump()
62
+ except Exception as e:
63
+ raise HTTPException(status_code=400, detail=str(e))
64
+
65
+
66
+ @app.post("/step")
67
+ async def step(request: StepRequest):
68
+ try:
69
+ action = DataCleanAction(
70
+ action_type=request.action_type,
71
+ target_field=request.target_field,
72
+ target_row=request.target_row,
73
+ new_value=request.new_value,
74
+ )
75
+ obs = env.step(action)
76
+ return obs.model_dump()
77
+ except Exception as e:
78
+ raise HTTPException(status_code=400, detail=str(e))
79
+
80
+
81
+ @app.get("/state")
82
+ async def state():
83
+ try:
84
+ s = env.state()
85
+ return s.model_dump()
86
+ except Exception as e:
87
+ raise HTTPException(status_code=400, detail=str(e))
88
+
89
+
90
+ @app.get("/tasks")
91
+ async def tasks():
92
+ return {"tasks": get_task_names()}
93
+
94
+
95
+ @app.websocket("/ws")
96
+ async def websocket_endpoint(websocket: WebSocket):
97
+ await websocket.accept()
98
+ ws_env = DataValidationEnvironment()
99
+
100
+ try:
101
+ while True:
102
+ data = await websocket.receive_text()
103
+ msg = json.loads(data)
104
+
105
+ method = msg.get("method", "")
106
+ params = msg.get("params", {})
107
+
108
+ try:
109
+ if method == "reset":
110
+ obs = ws_env.reset(
111
+ task_name=params.get("task_name"),
112
+ seed=params.get("seed", 42)
113
+ )
114
+ response = {
115
+ "type": "reset",
116
+ "observation": obs.model_dump(),
117
+ "reward": 0.0,
118
+ "done": False,
119
+ }
120
+ elif method == "step":
121
+ action = DataCleanAction(**params)
122
+ obs = ws_env.step(action)
123
+ response = {
124
+ "type": "step",
125
+ "observation": obs.model_dump(),
126
+ "reward": obs.reward,
127
+ "done": obs.done,
128
+ }
129
+ elif method == "state":
130
+ s = ws_env.state()
131
+ response = {
132
+ "type": "state",
133
+ "state": s.model_dump(),
134
+ }
135
+ else:
136
+ response = {"error": f"Unknown method: {method}"}
137
+
138
+ await websocket.send_text(json.dumps(response))
139
+ except Exception as e:
140
+ await websocket.send_text(json.dumps({
141
+ "error": str(e),
142
+ "traceback": traceback.format_exc()
143
+ }))
144
+ except WebSocketDisconnect:
145
+ pass
146
+
147
+
148
+ def main():
149
+ import uvicorn
150
+ uvicorn.run(app, host="0.0.0.0", port=8000)
151
+
152
+
153
+ if __name__ == "__main__":
154
+ main()
uv.lock ADDED
The diff for this file is too large to render. See raw diff