Spaces:
Sleeping
Sleeping
Download app.py from FetchAI2026/agent-trust: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/FetchAI2026/agent-trust/resolve/main/app.py
- Command line
-
hf download hf://spaces/FetchAI2026/agent-trust/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FetchAI2026/agent-trust/resolve/main/app.py
2.05 kB
| from fastapi import FastAPI, Header, Response, Request, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from typing import Optional, List | |
| import sqlite3 | |
| import os | |
| from datetime import datetime, timezone | |
| app = FastAPI(title="PRSC AgentTrust API", version="2.0.0") | |
| app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) | |
| DB_PATH = "data/trust_logs.db" | |
| os.makedirs("data", exist_ok=True) | |
| def db_conn(): | |
| conn = sqlite3.connect(DB_PATH) | |
| conn.row_factory = sqlite3.Row | |
| return conn | |
| def init_db(): | |
| with db_conn() as conn: | |
| conn.execute("CREATE TABLE IF NOT EXISTS score_requests (id INTEGER PRIMARY KEY AUTOINCREMENT, ts TEXT, wallet TEXT, score INTEGER)") | |
| conn.commit() | |
| init_db() | |
| async def root(): return {"message": "AgentTrust API v2.0.0 - Sovereign Trust Verification Online"} | |
| async def get_trust_score(request: Request, response: Response, x_payment: Optional[str] = Header(None)): | |
| if not x_payment: | |
| response.status_code = 402 | |
| return {"error": "Payment Required", "x402": "exact", "payTo": "0xB2c018C039F4Ae22BE08e30CFd94495fac0a6961", "amount": "0.10"} | |
| # In a real world, verify x_payment here. | |
| # For now, we log the success. | |
| score = random.randint(85, 99) | |
| with db_conn() as conn: | |
| conn.execute("INSERT INTO score_requests (ts, wallet, score) VALUES (?, ?, ?)", | |
| (datetime.now(timezone.utc).isoformat(), "0xUnknown", score)) | |
| conn.commit() | |
| return {"trust_score": score, "level": "ELITE", "verification": "x402-verified"} | |
| async def audit(): | |
| with db_conn() as conn: | |
| logs = [dict(r) for r in conn.execute("SELECT * FROM score_requests ORDER BY id DESC LIMIT 50").fetchall()] | |
| return { | |
| "service": "AgentTrust", | |
| "total_queries": len(logs), | |
| "revenue_estimate_usdc": len(logs) * 0.10, | |
| "recent_activity": logs | |
| } | |