Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,45 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
-
from
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
"reporting_lag": reporting_lag
|
| 11 |
-
}
|
| 12 |
-
return run_harmonization(request)
|
| 13 |
-
|
| 14 |
-
demo = gr.Interface(
|
| 15 |
-
fn=handle_submit,
|
| 16 |
-
inputs=[
|
| 17 |
-
gr.Dropdown(["Gold", "Iron Ore", "Oil", "Copper"], label="Commodity"),
|
| 18 |
-
gr.Number(value=950, label="Physical Anchor"),
|
| 19 |
-
gr.Slider(0, 30, step=1, label="Reporting Lag (days)")
|
| 20 |
-
],
|
| 21 |
-
outputs=gr.JSON(label="Result"),
|
| 22 |
-
title="CodexFlow ΩΞ • Economic Web Service",
|
| 23 |
-
description="Harmonized economic state + proof bundle"
|
| 24 |
)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# api.py
|
| 2 |
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
from economic_service import harmonize
|
| 6 |
+
from proof_engine import generate_proof
|
| 7 |
+
from federation import package_for_federation
|
| 8 |
|
| 9 |
+
app = FastAPI(
|
| 10 |
+
title="CodexFlow ΩΞ API",
|
| 11 |
+
description="Autonomous Economic Harmonization Web Service",
|
| 12 |
+
version="1.0.0",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
+
class HarmonizationRequest(BaseModel):
|
| 16 |
+
commodity: str
|
| 17 |
+
physical_anchor: float
|
| 18 |
+
reporting_lag: int
|
| 19 |
+
|
| 20 |
+
@app.get("/")
|
| 21 |
+
def root():
|
| 22 |
+
return {
|
| 23 |
+
"service": "CodexFlow ΩΞ",
|
| 24 |
+
"status": "online",
|
| 25 |
+
"mode": "simulation",
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
@app.post("/harmonize")
|
| 29 |
+
def harmonize_endpoint(req: HarmonizationRequest):
|
| 30 |
+
input_data = req.dict()
|
| 31 |
+
|
| 32 |
+
result = harmonize(
|
| 33 |
+
commodity=req.commodity,
|
| 34 |
+
physical_anchor=req.physical_anchor,
|
| 35 |
+
reporting_lag=req.reporting_lag,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
proof = generate_proof(input_data, result)
|
| 39 |
+
|
| 40 |
+
response = {
|
| 41 |
+
"result": result,
|
| 42 |
+
"proof": proof,
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
return package_for_federation(response)
|