Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- openenv.yaml +1 -1
- server/app.py +23 -25
openenv.yaml
CHANGED
|
@@ -3,7 +3,7 @@ name: lint_coding_agent
|
|
| 3 |
type: space
|
| 4 |
runtime: fastapi
|
| 5 |
app: server.app:app
|
| 6 |
-
port:
|
| 7 |
tasks:
|
| 8 |
- id: syntax-fix-lvl1
|
| 9 |
name: "Basic Syntax Error"
|
|
|
|
| 3 |
type: space
|
| 4 |
runtime: fastapi
|
| 5 |
app: server.app:app
|
| 6 |
+
port: 7860
|
| 7 |
tasks:
|
| 8 |
- id: syntax-fix-lvl1
|
| 9 |
name: "Basic Syntax Error"
|
server/app.py
CHANGED
|
@@ -8,6 +8,7 @@ import uvicorn
|
|
| 8 |
import logging
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 11 |
|
| 12 |
# --- ELITE LOGGING SETUP ---
|
| 13 |
logging.basicConfig(
|
|
@@ -17,10 +18,10 @@ logging.basicConfig(
|
|
| 17 |
logger = logging.getLogger("ArchitectApp")
|
| 18 |
|
| 19 |
# --- ARCHITECT'S PATH INJECTION ---
|
| 20 |
-
# Ensures 'models' and environment logic are discoverable regardless of the launch root
|
| 21 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
project_root = os.path.abspath(os.path.join(current_dir, ".."))
|
| 23 |
|
|
|
|
| 24 |
for path in [project_root, current_dir, os.getcwd()]:
|
| 25 |
if path not in sys.path:
|
| 26 |
sys.path.insert(0, path)
|
|
@@ -36,21 +37,24 @@ from models import LintCodingAgentAction, LintCodingAgentObservation
|
|
| 36 |
from server.lint_coding_agent_environment import LintCodingAgentEnvironment
|
| 37 |
|
| 38 |
# --- APP FACTORY ---
|
| 39 |
-
# 1. Create the internal
|
| 40 |
base_app = create_app(
|
| 41 |
LintCodingAgentEnvironment,
|
| 42 |
LintCodingAgentAction,
|
| 43 |
LintCodingAgentObservation,
|
| 44 |
)
|
| 45 |
|
| 46 |
-
# 2.
|
| 47 |
-
# redirect_slashes=False is non-negotiable for Hugging Face Proxy stability
|
| 48 |
app = FastAPI(
|
| 49 |
title="AnonAjay Architect API",
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
-
# --- DEBUG
|
| 54 |
@app.middleware("http")
|
| 55 |
async def debug_logging(request: Request, call_next):
|
| 56 |
logger.info(f"π‘ Incoming: {request.method} {request.url.path}")
|
|
@@ -58,16 +62,16 @@ async def debug_logging(request: Request, call_next):
|
|
| 58 |
logger.info(f"β
Outcome: {response.status_code}")
|
| 59 |
return response
|
| 60 |
|
| 61 |
-
# --- MOUNTING
|
| 62 |
-
# Explicitly map the root of /v1 to prevent the 404s seen in previous logs
|
| 63 |
@app.get("/v1")
|
| 64 |
async def v1_root():
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
-
# Mount the OpenEnv
|
| 68 |
app.mount("/v1", base_app)
|
| 69 |
|
| 70 |
-
# --- CORS &
|
| 71 |
app.add_middleware(
|
| 72 |
CORSMiddleware,
|
| 73 |
allow_origins=["*"],
|
|
@@ -78,27 +82,21 @@ app.add_middleware(
|
|
| 78 |
|
| 79 |
@app.get("/health")
|
| 80 |
def health_check():
|
| 81 |
-
"""
|
| 82 |
-
return {"status": "online", "port": 7860, "vfs_ready": True}
|
| 83 |
|
| 84 |
@app.get("/")
|
| 85 |
-
def
|
| 86 |
-
"""
|
| 87 |
-
return
|
| 88 |
-
"message": "Lead Architect Server Live",
|
| 89 |
-
"v1_docs": "/v1/docs",
|
| 90 |
-
"health": "/health"
|
| 91 |
-
}
|
| 92 |
|
| 93 |
def main():
|
| 94 |
-
"""
|
| 95 |
-
#
|
| 96 |
port = int(os.environ.get("PORT", 7860))
|
| 97 |
|
| 98 |
-
logger.info(f"π
|
| 99 |
-
logger.info(f"π
|
| 100 |
|
| 101 |
-
# proxy_headers + forwarded_allow_ips are vital for HF reverse proxy support
|
| 102 |
uvicorn.run(
|
| 103 |
app,
|
| 104 |
host="0.0.0.0",
|
|
|
|
| 8 |
import logging
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
from fastapi.responses import RedirectResponse
|
| 12 |
|
| 13 |
# --- ELITE LOGGING SETUP ---
|
| 14 |
logging.basicConfig(
|
|
|
|
| 18 |
logger = logging.getLogger("ArchitectApp")
|
| 19 |
|
| 20 |
# --- ARCHITECT'S PATH INJECTION ---
|
|
|
|
| 21 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
project_root = os.path.abspath(os.path.join(current_dir, ".."))
|
| 23 |
|
| 24 |
+
# Injecting all possible roots for the module loader
|
| 25 |
for path in [project_root, current_dir, os.getcwd()]:
|
| 26 |
if path not in sys.path:
|
| 27 |
sys.path.insert(0, path)
|
|
|
|
| 37 |
from server.lint_coding_agent_environment import LintCodingAgentEnvironment
|
| 38 |
|
| 39 |
# --- APP FACTORY ---
|
| 40 |
+
# 1. Create the internal engine
|
| 41 |
base_app = create_app(
|
| 42 |
LintCodingAgentEnvironment,
|
| 43 |
LintCodingAgentAction,
|
| 44 |
LintCodingAgentObservation,
|
| 45 |
)
|
| 46 |
|
| 47 |
+
# 2. Main Wrapper - Crucial config for Hugging Face UI restoration
|
|
|
|
| 48 |
app = FastAPI(
|
| 49 |
title="AnonAjay Architect API",
|
| 50 |
+
description="Meta x HF Hackathon: Multi-Lang Lint Coding Agent",
|
| 51 |
+
version="1.0.0",
|
| 52 |
+
redirect_slashes=False, # KILLER FIX: Prevents 307 loops that hide the UI
|
| 53 |
+
docs_url="/docs", # Direct UI access
|
| 54 |
+
openapi_url="/openapi.json"
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# --- DEBUG TELEMETRY ---
|
| 58 |
@app.middleware("http")
|
| 59 |
async def debug_logging(request: Request, call_next):
|
| 60 |
logger.info(f"π‘ Incoming: {request.method} {request.url.path}")
|
|
|
|
| 62 |
logger.info(f"β
Outcome: {response.status_code}")
|
| 63 |
return response
|
| 64 |
|
| 65 |
+
# --- MOUNTING STRATEGY ---
|
|
|
|
| 66 |
@app.get("/v1")
|
| 67 |
async def v1_root():
|
| 68 |
+
"""Explicitly defined to prevent 404s on the mount root."""
|
| 69 |
+
return {"message": "OpenEnv API v1 is active", "ui": "/v1/docs"}
|
| 70 |
|
| 71 |
+
# Mount the OpenEnv core
|
| 72 |
app.mount("/v1", base_app)
|
| 73 |
|
| 74 |
+
# --- CORS & INFRASTRUCTURE ---
|
| 75 |
app.add_middleware(
|
| 76 |
CORSMiddleware,
|
| 77 |
allow_origins=["*"],
|
|
|
|
| 82 |
|
| 83 |
@app.get("/health")
|
| 84 |
def health_check():
|
| 85 |
+
return {"status": "online", "engine": "LintCodingAgent", "port": 7860}
|
|
|
|
| 86 |
|
| 87 |
@app.get("/")
|
| 88 |
+
def home():
|
| 89 |
+
"""Automatically redirect root visitors to the documentation."""
|
| 90 |
+
return RedirectResponse(url="/v1/docs")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
def main():
|
| 93 |
+
"""Hugging Face Entry Point."""
|
| 94 |
+
# Standard HF Spaces use port 7860
|
| 95 |
port = int(os.environ.get("PORT", 7860))
|
| 96 |
|
| 97 |
+
logger.info(f"π Lead Architect Server spinning up on port {port}")
|
| 98 |
+
logger.info(f"π Docs available at: https://anonajay-lint-coding-agent.hf.space/v1/docs")
|
| 99 |
|
|
|
|
| 100 |
uvicorn.run(
|
| 101 |
app,
|
| 102 |
host="0.0.0.0",
|