rsaibhargav commited on
Commit
aea798e
Β·
verified Β·
1 Parent(s): 71cb877

Upload folder using huggingface_hub

Browse files
inference.py CHANGED
@@ -258,11 +258,52 @@ def get_model_answer(
258
  return answer
259
 
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  # ─── Main loop ──────────────────────────────────────────────────────────────
262
  async def main() -> None:
263
  client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)
264
 
265
  env_url = os.getenv("ENV_URL", "http://localhost:7860")
 
 
 
 
 
 
 
 
266
  env = CodeAssessmentEnv(base_url=env_url)
267
 
268
  rewards: List[float] = []
@@ -337,6 +378,8 @@ async def main() -> None:
337
  except Exception as exc:
338
  print(f"Close error: {exc}", file=sys.stderr, flush=True)
339
  log_end(success=success, steps=steps_taken, rewards=rewards)
 
 
340
 
341
 
342
  if __name__ == "__main__":
 
258
  return answer
259
 
260
 
261
+ # ─── Server startup ─────────────────────────────────────────────────────────
262
+ import subprocess
263
+ import time
264
+
265
+
266
+ def start_server() -> subprocess.Popen:
267
+ """Start the environment server as a background subprocess."""
268
+ script_dir = os.path.dirname(os.path.abspath(__file__))
269
+ proc = subprocess.Popen(
270
+ [sys.executable, "-m", "uvicorn", "server.app:app",
271
+ "--host", "0.0.0.0", "--port", "7860"],
272
+ cwd=script_dir,
273
+ stdout=subprocess.DEVNULL,
274
+ stderr=subprocess.DEVNULL,
275
+ )
276
+ return proc
277
+
278
+
279
+ def wait_for_server(url: str, timeout: int = 30) -> bool:
280
+ """Wait until the server responds."""
281
+ deadline = time.time() + timeout
282
+ while time.time() < deadline:
283
+ try:
284
+ import urllib.request
285
+ req = urllib.request.urlopen(f"{url}/health", timeout=3)
286
+ if req.status == 200:
287
+ return True
288
+ except Exception:
289
+ pass
290
+ time.sleep(1)
291
+ return False
292
+
293
+
294
  # ─── Main loop ──────────────────────────────────────────────────────────────
295
  async def main() -> None:
296
  client = OpenAI(base_url=API_BASE_URL, api_key=HF_TOKEN)
297
 
298
  env_url = os.getenv("ENV_URL", "http://localhost:7860")
299
+ server_proc = None
300
+
301
+ # Start the server if it's not already running
302
+ if not wait_for_server(env_url, timeout=3):
303
+ server_proc = start_server()
304
+ if not wait_for_server(env_url, timeout=30):
305
+ print("Server failed to start", file=sys.stderr, flush=True)
306
+
307
  env = CodeAssessmentEnv(base_url=env_url)
308
 
309
  rewards: List[float] = []
 
378
  except Exception as exc:
379
  print(f"Close error: {exc}", file=sys.stderr, flush=True)
380
  log_end(success=success, steps=steps_taken, rewards=rewards)
381
+ if server_proc:
382
+ server_proc.terminate()
383
 
384
 
385
  if __name__ == "__main__":
openenv_code_assessment_env.egg-info/PKG-INFO ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.4
2
+ Name: openenv-code-assessment-env
3
+ Version: 0.1.0
4
+ Summary: OpenEnv RL environment for AI response evaluation β€” correctness, tone appropriateness, and multi-dimensional quality scoring across structured user profiles
5
+ Requires-Python: >=3.10
6
+ License-File: LICENSE
7
+ Requires-Dist: openenv-core[core]>=0.2.1
8
+ Provides-Extra: dev
9
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
10
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
11
+ Dynamic: license-file
openenv_code_assessment_env.egg-info/SOURCES.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ ./__init__.py
5
+ ./client.py
6
+ ./demo.py
7
+ ./inference.py
8
+ ./models.py
9
+ ./test_graders.py
10
+ ./validate_graders.py
11
+ openenv_code_assessment_env.egg-info/PKG-INFO
12
+ openenv_code_assessment_env.egg-info/SOURCES.txt
13
+ openenv_code_assessment_env.egg-info/dependency_links.txt
14
+ openenv_code_assessment_env.egg-info/entry_points.txt
15
+ openenv_code_assessment_env.egg-info/requires.txt
16
+ openenv_code_assessment_env.egg-info/top_level.txt
17
+ server/__init__.py
18
+ server/app.py
19
+ server/code_assessment_environment.py
openenv_code_assessment_env.egg-info/dependency_links.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
openenv_code_assessment_env.egg-info/entry_points.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [console_scripts]
2
+ server = code_assessment_env.server.app:main
openenv_code_assessment_env.egg-info/requires.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ openenv-core[core]>=0.2.1
2
+
3
+ [dev]
4
+ pytest>=8.0.0
5
+ pytest-cov>=4.0.0
openenv_code_assessment_env.egg-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ code_assessment_env