LordXido commited on
Commit
b458dab
·
verified ·
1 Parent(s): dde3346

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -21
app.py CHANGED
@@ -1,30 +1,146 @@
1
  import gradio as gr
2
- from ingest import ingest_physical_metrics, load_schema
3
- from core_engine import harmonize_price
4
- from cashflow import accelerate_receivable
5
- from utils import compute_risk_score
6
 
7
- def codexflow_endpoint(raw_price: float, inventory_val: float):
8
- physical = ingest_physical_metrics("placeholder")
9
- schema = load_schema()
10
 
11
- harm = harmonize_price(raw_price, physical["production"], physical["transport_delay"] / 10)
12
- risk = compute_risk_score(harm["confidence"], inventory_val)
 
13
 
14
- accelerated = accelerate_receivable(raw_price, physical["transport_delay"], risk)
 
 
 
 
 
 
 
 
 
 
15
 
16
  return {
17
- "harmonized": harm,
18
- "risk_score": risk,
19
- "accelerated_cashflow": accelerated
 
20
  }
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  with gr.Blocks() as demo:
23
- gr.Markdown("# CodexFlow ΩΞ – Cashflow Accelerator")
24
- raw_price = gr.Number(label="Raw Market Price")
25
- inventory_val = gr.Number(label="Inventory Confidence (0-1)")
26
- btn = gr.Button("Compute")
27
- output = gr.JSON()
28
- btn.click(codexflow_endpoint, inputs=[raw_price, inventory_val], outputs=output)
29
-
30
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from datetime import datetime
3
+ from typing import Dict
 
 
4
 
 
 
 
5
 
6
+ # =========================
7
+ # CORE CODEX ENGINE
8
+ # =========================
9
 
10
+ def harmonize_price(
11
+ synthetic_price: float,
12
+ physical_anchor: float,
13
+ lag_factor: float
14
+ ) -> Dict[str, float]:
15
+ """
16
+ Harmonize synthetic price signals with physical reality.
17
+ """
18
+ correction = (synthetic_price - physical_anchor) * min(1.0, lag_factor)
19
+ harmonized = synthetic_price - correction
20
+ confidence = 1.0 - abs(correction) / max(synthetic_price, 1.0)
21
 
22
  return {
23
+ "synthetic_price_index": round(synthetic_price, 2),
24
+ "correction": round(-correction, 2),
25
+ "harmonized_price_index": round(harmonized, 2),
26
+ "confidence": round(max(0.0, min(confidence, 1.0)), 2)
27
  }
28
 
29
+
30
+ def accelerate_cashflow(
31
+ amount: float,
32
+ days_delay: int,
33
+ confidence: float
34
+ ) -> float:
35
+ """
36
+ Time-value cashflow acceleration (non-speculative).
37
+ """
38
+ base_rate = 0.03
39
+ risk_penalty = (1.0 - confidence) * 0.05
40
+ discount_rate = base_rate + risk_penalty
41
+
42
+ accelerated_value = amount / ((1 + discount_rate) ** (days_delay / 365))
43
+ return round(accelerated_value, 2)
44
+
45
+
46
+ # =========================
47
+ # SYSTEM ENTRYPOINT
48
+ # =========================
49
+
50
+ def codexflow_runtime(
51
+ commodity: str,
52
+ synthetic_price: float,
53
+ physical_price: float,
54
+ reporting_lag_days: int
55
+ ) -> Dict:
56
+ """
57
+ Full CodexFlow runtime execution.
58
+ """
59
+ lag_factor = min(reporting_lag_days / 10, 1.0)
60
+
61
+ harmonized = harmonize_price(
62
+ synthetic_price=synthetic_price,
63
+ physical_anchor=physical_price,
64
+ lag_factor=lag_factor
65
+ )
66
+
67
+ accelerated_cashflow = accelerate_cashflow(
68
+ amount=harmonized["harmonized_price_index"],
69
+ days_delay=reporting_lag_days,
70
+ confidence=harmonized["confidence"]
71
+ )
72
+
73
+ return {
74
+ "status": "ok",
75
+ "engine": "CodexFlow ΩΞ",
76
+ "timestamp": datetime.utcnow().isoformat(),
77
+ "commodity": commodity,
78
+ "harmonized_state": harmonized,
79
+ "accelerated_cashflow_estimate": accelerated_cashflow
80
+ }
81
+
82
+
83
+ # =========================
84
+ # GRADIO UI
85
+ # =========================
86
+
87
  with gr.Blocks() as demo:
88
+ gr.Markdown(
89
+ """
90
+ # CodexFlow ΩΞ Runtime
91
+ **Reality-Anchored Cashflow Acceleration Engine**
92
+
93
+ Harmonizes synthetic market signals with physical reality and
94
+ accelerates cashflow without speculation or leverage.
95
+ """
96
+ )
97
+
98
+ with gr.Row():
99
+ commodity = gr.Dropdown(
100
+ ["Gold", "Iron Ore", "Crude Oil"],
101
+ label="Commodity"
102
+ )
103
+ synthetic_price = gr.Number(
104
+ label="Synthetic Price Index",
105
+ value=1000
106
+ )
107
+
108
+ with gr.Row():
109
+ physical_price = gr.Number(
110
+ label="Physical / Production Price Anchor",
111
+ value=950
112
+ )
113
+ reporting_lag = gr.Slider(
114
+ minimum=0,
115
+ maximum=30,
116
+ step=1,
117
+ label="Reporting Lag (Days)",
118
+ value=7
119
+ )
120
+
121
+ run_btn = gr.Button("Run CodexFlow Harmonization")
122
+ output = gr.JSON(label="CodexFlow Output")
123
+
124
+ run_btn.click(
125
+ codexflow_runtime,
126
+ inputs=[
127
+ commodity,
128
+ synthetic_price,
129
+ physical_price,
130
+ reporting_lag
131
+ ],
132
+ outputs=output
133
+ )
134
+
135
+
136
+ # =========================
137
+ # HUGGING FACE PATCH
138
+ # =========================
139
+
140
+ if __name__ == "__main__":
141
+ demo.launch(
142
+ server_name="0.0.0.0",
143
+ server_port=7860,
144
+ show_error=True,
145
+ ssr_mode=False
146
+ )