Spaces:
Sleeping
Sleeping
Download server/app.py from Arun006/expense-agent-openenv: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/Arun006/expense-agent-openenv/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/Arun006/expense-agent-openenv/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Arun006/expense-agent-openenv/resolve/main/server/app.py
1.54 kB
| import sys | |
| import os | |
| # Ensure /app is on the path regardless of launch method | |
| _app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| if _app_dir not in sys.path: | |
| sys.path.insert(0, _app_dir) | |
| from fastapi import FastAPI, Request | |
| from env import create_env | |
| import uvicorn | |
| app = FastAPI() | |
| def root(): | |
| return {"status": "running"} | |
| async def reset(request: Request): | |
| try: | |
| if request.method == "POST": | |
| try: | |
| body = await request.json() | |
| except: | |
| body = {} | |
| task = body.get("task", "easy") | |
| else: | |
| task = "easy" | |
| env = create_env(task) | |
| obs = env.reset() | |
| return { | |
| "status": "ok", | |
| "task": task, | |
| "observation": str(obs) | |
| } | |
| except Exception as e: | |
| return {"error": str(e)} | |
| async def step(request: Request): | |
| try: | |
| body = await request.json() | |
| action = body.get("action") | |
| env = create_env() | |
| env.reset() | |
| obs, reward, done, info = env.step(action) | |
| return { | |
| "observation": str(obs), | |
| "reward": reward, | |
| "done": done, | |
| "info": info | |
| } | |
| except Exception as e: | |
| return {"error": str(e)} | |
| # ✅ REQUIRED MAIN FUNCTION | |
| def main(): | |
| uvicorn.run("server.app:app", host="0.0.0.0", port=7860) | |
| # ✅ REQUIRED ENTRY POINT | |
| if __name__ == "__main__": | |
| main() | |