vinith17 commited on
Commit
f7a26b5
·
1 Parent(s): 56f6a4d

Fix endpoint registration and app structure for Hugging Face Spaces compatibility

Browse files
Files changed (2) hide show
  1. app.py +2 -0
  2. main.py +28 -15
app.py CHANGED
@@ -12,6 +12,8 @@ openenv_path = os.path.join(os.path.dirname(__file__), "openenv-course-tmp")
12
  if os.path.exists(openenv_path) and openenv_path not in sys.path:
13
  sys.path.insert(0, openenv_path)
14
 
 
 
15
  from main import app
16
 
17
  __all__ = ["app"]
 
12
  if os.path.exists(openenv_path) and openenv_path not in sys.path:
13
  sys.path.insert(0, openenv_path)
14
 
15
+
16
+ # Ensure only the correct FastAPI app is exposed for Hugging Face Spaces
17
  from main import app
18
 
19
  __all__ = ["app"]
main.py CHANGED
@@ -1,16 +1,33 @@
 
 
 
 
 
1
  from training_loop import run_training
 
 
 
 
 
 
 
 
 
 
2
 
3
- # Endpoint to trigger RL training
4
- from fastapi import Query
 
 
 
 
 
 
5
 
6
- @app.post("/api/train")
7
- async def run_real_training(episodes: int = Query(5, description="Number of training episodes to run")):
8
- """
9
- Run the RL training loop for the specified number of episodes.
10
- Returns training stats and summary.
11
- """
12
- stats = run_training(num_episodes=episodes, verbose=False)
13
- return {"status": "ok", "stats": stats}
14
  from openenv.core.env_server import create_fastapi_app
15
  from environment import CodeBugEnvironment
16
  from models import CodeReviewAction, CodeReviewObservation, CodeReviewState
@@ -32,11 +49,7 @@ except ImportError:
32
 
33
  logger = logging.getLogger(__name__)
34
 
35
- app = create_fastapi_app(
36
- CodeBugEnvironment,
37
- CodeReviewAction,
38
- CodeReviewObservation
39
- )
40
 
41
  @app.get("/")
42
  def serve_frontend():
 
1
+ import os
2
+ import json
3
+ import re
4
+ import logging
5
+ from fastapi import Query
6
  from training_loop import run_training
7
+ app = None
8
+ def create_app():
9
+ global app
10
+ if app is not None:
11
+ return app
12
+ app_ = create_fastapi_app(
13
+ CodeBugEnvironment,
14
+ CodeReviewAction,
15
+ CodeReviewObservation
16
+ )
17
 
18
+ @app_.post("/api/train")
19
+ async def run_real_training(episodes: int = Query(5, description="Number of training episodes to run")):
20
+ """
21
+ Run the RL training loop for the specified number of episodes.
22
+ Returns training stats and summary.
23
+ """
24
+ stats = run_training(num_episodes=episodes, verbose=False)
25
+ return {"status": "ok", "stats": stats}
26
 
27
+ # ...existing endpoints (review, health, stats, etc.) will be added below...
28
+ return app_
29
+
30
+ app = create_app()
 
 
 
 
31
  from openenv.core.env_server import create_fastapi_app
32
  from environment import CodeBugEnvironment
33
  from models import CodeReviewAction, CodeReviewObservation, CodeReviewState
 
49
 
50
  logger = logging.getLogger(__name__)
51
 
52
+
 
 
 
 
53
 
54
  @app.get("/")
55
  def serve_frontend():