LordXido commited on
Commit
c2dc6f6
Β·
verified Β·
1 Parent(s): 8f5e96d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -38
app.py CHANGED
@@ -1,44 +1,111 @@
1
  import gradio as gr
2
- from codexflow_core import CodexFlowEngine
3
-
4
- # Instantiate the core engine once
5
- engine = CodexFlowEngine()
6
-
7
- def run_codexflow(contract_json: str):
8
- """
9
- Main UI handler for CodexFlow_TM:
10
- - Accepts a JSON contract or cashflow spec
11
- - Executes distortion/confidence logic + enforced reconciliation
12
- - Returns structured system output
13
- """
14
- try:
15
- result = engine.process(contract_json)
 
 
 
 
 
 
16
  return {
17
- "status": "OK",
18
- "distortion_index": result["distortion"],
19
- "confidence_score": result["confidence"],
20
- "harmonized_state": result["harmonized"],
21
- "messages": result.get("messages", [])
22
  }
23
- except Exception as e:
24
- return {"status": "ERROR", "message": str(e)}
25
-
26
- demo = gr.Interface(
27
- fn=run_codexflow,
28
- inputs=gr.Textbox(
29
- label="CodexFlow Contract / Specification (JSON)",
30
- placeholder='{"type":"cashflow","terms":{...}}',
31
- lines=10
32
- ),
33
- outputs=gr.JSON(label="CodexFlow System Output"),
34
- title="CodexFlowβ„’ β€” Global Cashflow Orchestrator",
35
- description=(
36
- "Paste your CodexFlow contract or cashflow declaration. "
37
- "The system evaluates distortion, confidence, "
38
- "and produces harmonized state signals."
39
- ),
40
- theme="default"
41
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  if __name__ == "__main__":
44
  demo.launch()
 
1
  import gradio as gr
2
+ from datetime import datetime
3
+
4
+ from core_engine import run_engine
5
+ from ingest import normalize_input
6
+ from utils import validate_api_key
7
+
8
+
9
+ # ─────────────────────────────────────────────
10
+ # CodexFlow ΩΞ Execution Bridge
11
+ # ─────────────────────────────────────────────
12
+
13
+ def codexflow_execute(
14
+ api_key: str,
15
+ commodity: str,
16
+ physical_anchor: float,
17
+ reporting_lag: int,
18
+ use_live_feed: bool
19
+ ):
20
+ # --- Security gate ---
21
+ if not validate_api_key(api_key):
22
  return {
23
+ "status": "ERROR",
24
+ "message": "Invalid or missing API key"
 
 
 
25
  }
26
+
27
+ # --- Normalize input ---
28
+ payload = normalize_input(
29
+ commodity=commodity,
30
+ physical_anchor=physical_anchor,
31
+ reporting_lag=reporting_lag,
32
+ live_feed=use_live_feed
33
+ )
34
+
35
+ # --- Execute CodexFlow engine ---
36
+ result = run_engine(payload)
37
+
38
+ return {
39
+ "status": "OK",
40
+ "engine": "CodexFlow ΩΞ",
41
+ "timestamp": datetime.utcnow().isoformat() + "Z",
42
+ "input": payload,
43
+ "output": result
44
+ }
45
+
46
+
47
+ # ─────────────────────────────────────────────
48
+ # Hugging Face UI
49
+ # ─────────────────────────────────────────────
50
+
51
+ with gr.Blocks(title="CodexFlow ΩΞ") as demo:
52
+
53
+ gr.Markdown(
54
+ """
55
+ # CodexFlow ΩΞ
56
+ **Autonomous Economic Reflex Operating System**
57
+
58
+ Harmonizes global economic signals by correcting:
59
+ β€’ reporting lag
60
+ β€’ synthetic distortion
61
+ β€’ physical supply mismatch
62
+ """
63
+ )
64
+
65
+ api_key = gr.Textbox(
66
+ label="API Key",
67
+ type="password",
68
+ placeholder="Enter API key"
69
+ )
70
+
71
+ commodity = gr.Dropdown(
72
+ ["Gold", "Iron Ore", "Oil", "Copper"],
73
+ value="Gold",
74
+ label="Commodity"
75
+ )
76
+
77
+ physical_anchor = gr.Number(
78
+ label="Physical Anchor",
79
+ value=950
80
+ )
81
+
82
+ reporting_lag = gr.Slider(
83
+ minimum=0,
84
+ maximum=30,
85
+ value=7,
86
+ step=1,
87
+ label="Reporting Lag (Days)"
88
+ )
89
+
90
+ live_feed = gr.Checkbox(
91
+ value=True,
92
+ label="Use Live Exchange Feed"
93
+ )
94
+
95
+ execute_btn = gr.Button("Execute")
96
+ output = gr.JSON(label="Result")
97
+
98
+ execute_btn.click(
99
+ fn=codexflow_execute,
100
+ inputs=[
101
+ api_key,
102
+ commodity,
103
+ physical_anchor,
104
+ reporting_lag,
105
+ live_feed
106
+ ],
107
+ outputs=output
108
+ )
109
 
110
  if __name__ == "__main__":
111
  demo.launch()