Spaces:
Runtime error
Runtime error
Download app.py from thisisgini/ecommerce_bot: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/thisisgini/ecommerce_bot/resolve/refs%2Fpr%2F1/app.py
- Command line
-
hf download hf://spaces/thisisgini/ecommerce_bot@refs/pr/1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/thisisgini/ecommerce_bot/resolve/refs%2Fpr%2F1/app.py
2 kB
| import sys | |
| import os | |
| from pathlib import Path | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from typing import Dict, Any | |
| # 1. Simplified Imports: Everything is in the same folder now! | |
| try: | |
| from models import Action, Observation | |
| from ecommerce_bot_environment import EcommerceBotEnvironment | |
| except ImportError as e: | |
| print(f"CRITICAL ERROR: Missing modules. Ensure models.py and ecommerce_bot_environment.py are in the root. {e}") | |
| sys.exit(1) | |
| # 2. Initialize FastAPI | |
| app = FastAPI( | |
| title="Meta x Scalar: OpenEnv Ecommerce Bot", | |
| description="Agentic System for Real-World E-commerce Automation", | |
| version="1.0.0" | |
| ) | |
| # 3. Add CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # 4. Initialize the Environment | |
| env = EcommerceBotEnvironment() | |
| # --- ROUTES --- | |
| async def root(): | |
| return { | |
| "message": "E-commerce Bot API is running", | |
| "status": "online", | |
| "spec": "OpenEnv v1.0", | |
| "location": "Mumbai University Hackathon Entry" | |
| } | |
| async def health(): | |
| return {"status": "healthy", "database": "connected"} | |
| async def get_state(): | |
| return { | |
| "status": "ready", | |
| "tasks": ["create_order", "update_address", "issue_refund"], | |
| "persistance": "sqlite3" | |
| } | |
| async def reset(): | |
| observation = env.reset() | |
| return observation | |
| async def step(action: Action): | |
| observation, reward, done, info = env.step(action) | |
| return { | |
| "observation": observation, | |
| "reward": float(reward), | |
| "done": bool(done), | |
| "info": info | |
| } | |
| def shutdown_event(): | |
| print("Shutting down E-commerce Bot Server...") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| # Hardcode to 7860 to guarantee the HF Load Balancer connects | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |