Spaces:
No application file
No application file
Download app.py from UPNISOLABS/APEX-Core-Node: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/UPNISOLABS/APEX-Core-Node/resolve/main/app.py
- Command line
-
hf download hf://spaces/UPNISOLABS/APEX-Core-Node/app.py
-
curl -L -o app.py https://huggingface.co/spaces/UPNISOLABS/APEX-Core-Node/resolve/main/app.py
1.55 kB
| from fastapi import FastAPI, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from typing import List, Optional | |
| # 1. Initialize the App | |
| app = FastAPI( | |
| title="Sentinel AI Backend", | |
| description="API for Blockchain Monitoring and AI Analysis", | |
| version="1.0.0" | |
| ) | |
| # 2. Enable CORS (Essential for React/Frontend to talk to this API) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # In production, replace "*" with your frontend URL | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # 3. Define Data Models (Schemas) | |
| class AnalysisRequest(BaseModel): | |
| tx_hash: str | |
| network: str = "ethereum" | |
| class AnalysisResponse(BaseModel): | |
| status: str | |
| risk_score: float | |
| threats: List[str] | |
| # 4. Routes/Endpoints | |
| async def root(): | |
| return {"message": "Sentinel AI Engine is Online", "port": 7860} | |
| async def analyze_transaction(request: AnalysisRequest): | |
| try: | |
| # Business logic goes here (e.g., calling an AI model or scanning a chain) | |
| return { | |
| "status": "completed", | |
| "risk_score": 0.12, | |
| "threats": [] | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| # 5. Run configuration (For local testing) | |
| if __name__ == "__main__": | |
| import uvicorn | |
| # Hugging Face Spaces and most cloud providers expect port 7860 or 8000 | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |