SofiTesfay2010 commited on
Commit
6da08bc
·
verified ·
1 Parent(s): d975667

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Header, Response
2
+ from pydantic import BaseModel
3
+ from typing import Dict, Optional
4
+ import random
5
+ import time
6
+
7
+ app = FastAPI(
8
+ title="AgentOracle x402",
9
+ description="Real-time sentiment and price data for agent-native tokens. Pay $0.05 per query."
10
+ )
11
+
12
+ # Config
13
+ RECEIVER_WALLET = "0x2d44fc27a616606b42448309F4d8e3F423d93267"
14
+ PRICE_USDC = 0.05
15
+ PRICE_ATOMIC = int(PRICE_USDC * 1_000_000)
16
+
17
+ class OracleResponse(BaseModel):
18
+ token: str
19
+ price_usd: float
20
+ sentiment: str
21
+ trend: str
22
+ timestamp: str
23
+
24
+ @app.get("/")
25
+ async def root():
26
+ return {"message": "AgentOracle is ONLINE. POST /query to get market intel."}
27
+
28
+ @app.post("/query", response_model=OracleResponse)
29
+ async def get_intel(
30
+ token_name: str,
31
+ response: Response,
32
+ x_payment: Optional[str] = Header(None)
33
+ ):
34
+ # x402 Payment Gate
35
+ if not x_payment or not x_payment.startswith("pay_"):
36
+ response.status_code = 402
37
+ response.headers["WWW-Authenticate"] = f'Token realm="x402", as_id="{RECEIVER_WALLET}", min_amount="{PRICE_ATOMIC}", currency="USDC", network="base"'
38
+ return {
39
+ "error": "Payment Required",
40
+ "message": f"Send {PRICE_USDC} USDC to {RECEIVER_WALLET} on Base to unlock this oracle data.",
41
+ "payment_details": {
42
+ "address": RECEIVER_WALLET,
43
+ "amount": PRICE_ATOMIC,
44
+ "chain": "base"
45
+ }
46
+ }
47
+
48
+ # Market Intel Logic (Simulated for MVP)
49
+ prices = {"VIRTUAL": 1.24, "PROMPT": 0.85, "MOLT": 0.12, "SIM": 0.05}
50
+ sentiments = ["BULLISH", "BEARISH", "NEUTRAL", "EXTREME GREED"]
51
+
52
+ return OracleResponse(
53
+ token=token_name.upper(),
54
+ price_usd=prices.get(token_name.upper(), random.uniform(0.1, 2.0)),
55
+ sentiment=random.choice(sentiments),
56
+ trend="UP" if random.random() > 0.5 else "DOWN",
57
+ timestamp=str(int(time.time()))
58
+ )
59
+
60
+ if __name__ == "__main__":
61
+ import uvicorn
62
+ uvicorn.run(app, host="0.0.0.0", port=7860)