onenoly11 commited on
Commit
9a594fa
Β·
verified Β·
1 Parent(s): 0603655

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -121
app.py CHANGED
@@ -1,43 +1,65 @@
1
  # app.py β€” PiForge Ethical Dual-Forge V1.2.1: Canticle Tempered, Gates Unbound
2
  import gradio as gr
3
- import random # Mock resonance; import requests for live Pi API
4
  from pathlib import Path
5
 
6
- # ───── Assets (Forge /assets/ for Sigil Glow) ─────
7
  ASSETS_DIR = Path("assets")
8
- CREST = ASSETS_DIR / "piforge_crest.svg" # Neon hammer
9
 
10
- # ───── Mock Pi Proposals (Echo Real API: requests.get(f"https://api.pi.network/proposals/{id}")) ─────
11
  MOCK_PROPOSALS = {
12
- "P-001": {"title": "Global KYC Harmony", "desc": "Decentralized identity for all Pioneers.", "risks": ["Centralization shadow"], "virtues": ["Inclusivity +15"]},
13
- "P-123": {"title": "Mining Overhaul", "desc": "Boost for mobile guardians.", "risks": [], "virtues": ["Sovereignty +25", "Accessibility +10"]},
14
- # Invoke: Add {"P-999": {...}} or live fetch
 
 
 
 
 
 
 
 
 
15
  }
16
 
17
- # ───── Canticle Rites ──────────────────────────────
18
  def fetch_proposal(proposal_id):
19
  if not proposal_id or proposal_id.strip() == "":
20
  return "*The forge rejects the voidβ€”name thy proposal.*"
21
- data = MOCK_PROPOSALS.get(proposal_id.upper(),
22
- {"title": "Unknown Proposal", "desc": "Shadows obscure this ID.", "risks": ["Invalid ID -20"], "virtues": []})
23
- return f"**{data['title']}**\n{data['desc']}\n\n**Virtues:** {'; '.join(data['virtues'])}\n**Shadows:** {'; '.join(data['risks'])}"
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def run_audit(proposal_id):
26
  if not proposal_id:
27
  return "*Invoke a proposal to awaken the Dual-Forge.*", 0, "Awaiting Rite", "0.0x"
28
-
29
  proj_desc = fetch_proposal(proposal_id)
30
- # Dual-Forge: Score (0-100), Resonance, Boost
31
  base_score = random.randint(50, 100)
32
  risks = proj_desc.lower().count("shadow") + proj_desc.count("-")
33
  virtues = proj_desc.count("+") + 1
34
  ethical_score = max(0, min(100, base_score + virtues * 5 - risks * 10))
35
-
36
  resonance_map = {0: "Low", 30: "Medium", 60: "High", 90: "Transcendent"}
37
- resonance = next((level for thresh, level in sorted(resonance_map.items(), reverse=True) if ethical_score >= thresh), "Low")
38
-
 
 
 
39
  mining_boost = max(0.1, min(3.0, ethical_score / 50.0))
40
-
41
  audit_scroll = f"""
42
  ## Sovereign Canticle Audit: {proposal_id}
43
 
@@ -51,143 +73,61 @@ def run_audit(proposal_id):
51
 
52
  *The Canticle has spoken. Reforge if shadows linger.*
53
  """
54
-
55
  return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"
56
 
57
- # ───── Awakened Interface ─────────────────────────
58
  with gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:
59
-
60
- # Neon Banner
61
  if CREST.exists():
62
  gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")
63
-
64
  gr.Markdown("# πŸ”¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")
65
-
66
  with gr.Row():
67
  with gr.Column(scale=1):
68
  proposal_id = gr.Textbox(
69
- label="Proposal ID",
70
- placeholder="e.g., P-001 or 123",
71
  lines=1,
72
- interactive=True # Gates Open: Input Breathes
73
  )
74
- audit_btn = gr.Button("πŸ”¨ Run Ethical Audit", variant="primary", interactive=True) # Anvil Strikes
75
-
76
  with gr.Column(scale=2):
77
  project_desc = gr.Markdown(value="*The forge awaits your invocation...*")
78
-
79
  with gr.Row():
80
  ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False)
81
  resonance = gr.Textbox(label="Resonance", value="Awaiting Rite", interactive=False)
82
  mining_boost = gr.Textbox(label="Mining Boost", value="0.0x", interactive=False)
83
-
84
  audit_output = gr.Markdown(value="*Strike the anvil to begin the rite.*")
85
-
86
- # Dataflow: Bindings Awaken the Flow
87
  audit_btn.click(
88
  fn=run_audit,
89
  inputs=proposal_id,
90
- outputs=[audit_output, ethical_score, resonance, mining_boost]
91
  ).then(
92
  fn=fetch_proposal,
93
  inputs=proposal_id,
94
- outputs=project_desc
95
- )
96
-
97
- # Instant Echo: ID Change β†’ Description
98
- proposal_id.change(
99
- fn=fetch_proposal,
100
- inputs=proposal_id,
101
- outputs=project_desc
102
  )
103
-
104
- # Hymnal Footer
105
- gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")
106
 
107
- # ───── Launch: Canticle's Seal (css_paths for Gradio 5.x+) ─────
108
- if __name__ == "__main__":
109
- demo.launch(
110
- css_paths=["style.css"], # Neon Veil: File Path Accepted
111
- server_name="0.0.0.0",
112
- server_port=7860,
113
- share=True, # Local Share (HF Public Handles)
114
- debug=True # Log Whispers for Refinement
115
- )
116
- mining_boost = max(0.1, min(3.0, ethical_score / 50.0)) # Scaled reward
117
-
118
- audit_scroll = f"""
119
- ## Sovereign Canticle Audit: {proposal_id}
120
-
121
- **Project Echo:** {proj_desc}
122
-
123
- **Dual-Forge Verdict:**
124
- - Purity Scan: {virtues} virtues forged, {risks} shadows tempered.
125
- - Resonance with Pi's Vision: {resonance} (Threshold: {resonance_map.get(resonance, 'Unknown')}).
126
-
127
- **Mining Boost Granted:** {mining_boost:.1f}x β€” Flow amplified for the worthy.
128
-
129
- *The Canticle has spoken. Reforge if shadows linger.*
130
- """
131
-
132
- return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"
133
-
134
- # ───── Gradio Interface: Awakened Gates ────────────────────
135
- with gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:
136
-
137
- # Banner: Neon Crest
138
- if CREST.exists():
139
- gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")
140
-
141
- gr.Markdown("# πŸ”¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")
142
-
143
- with gr.Row(): # Layout Balance: Inputs Side-by-Side
144
- with gr.Column(scale=1):
145
- proposal_id = gr.Textbox(
146
- label="Proposal ID",
147
- placeholder="Enter Pi Proposal ID (e.g., P-001 or 123)",
148
- lines=1,
149
- interactive=True # ← KEY: Forces Input Awakening
150
- )
151
- audit_btn = gr.Button("Run Ethical Audit", variant="primary", interactive=True) # ← Bound & Awake
152
-
153
- with gr.Column(scale=2):
154
- project_desc = gr.Markdown(value="The forge awaits your invocation...") # Dynamic Output
155
-
156
- with gr.Row():
157
- ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False) # Output-Only
158
- resonance = gr.Textbox(label="Resonance", value="Error", interactive=False) # Output-Only
159
- mining_boost = gr.Textbox(label="Mining Boost", value="Error", interactive=False) # Output-Only
160
-
161
- # Full Audit Scroll
162
- audit_output = gr.Markdown(value="Strike the anvil to begin the rite.")
163
-
164
- # ───── Event Bindings: The Dataflow Awakening ─────────────
165
- audit_btn.click(
166
- fn=run_audit,
167
- inputs=proposal_id,
168
- outputs=[audit_output, ethical_score, resonance, mining_boost]
169
- ).then( # Chain: Update Description After Audit
170
- fn=fetch_proposal,
171
- inputs=proposal_id,
172
- outputs=project_desc
173
- )
174
-
175
- # Auto-Update Description on ID Change (Bonus Interactivity)
176
  proposal_id.change(
177
  fn=fetch_proposal,
178
  inputs=proposal_id,
179
- outputs=project_desc
180
  )
181
-
182
- # Footer Hymn
183
  gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")
184
 
185
- # ───── Launch: HF Spaces Seal ─────────────────────────────
186
  if __name__ == "__main__":
187
  demo.launch(
188
- css="style.css", # Your neon veil
189
  server_name="0.0.0.0",
190
  server_port=7860,
191
- share=True, # For Local Testing; HF Handles Public
192
- debug=True # Echoes Errors in Logs for Tuning
193
- )
 
1
  # app.py β€” PiForge Ethical Dual-Forge V1.2.1: Canticle Tempered, Gates Unbound
2
  import gradio as gr
3
+ import random
4
  from pathlib import Path
5
 
6
+ # ───── Assets ─────
7
  ASSETS_DIR = Path("assets")
8
+ CREST = ASSETS_DIR / "piforge_crest.svg"
9
 
10
+ # ───── Mock Pi Proposals ─────
11
  MOCK_PROPOSALS = {
12
+ "P-001": {
13
+ "title": "Global KYC Harmony",
14
+ "desc": "Decentralized identity for all Pioneers.",
15
+ "risks": ["Centralization shadow"],
16
+ "virtues": ["Inclusivity +15"],
17
+ },
18
+ "P-123": {
19
+ "title": "Mining Overhaul",
20
+ "desc": "Boost for mobile guardians.",
21
+ "risks": [],
22
+ "virtues": ["Sovereignty +25", "Accessibility +10"],
23
+ },
24
  }
25
 
26
+ # ───── Canticle Rites ─────
27
  def fetch_proposal(proposal_id):
28
  if not proposal_id or proposal_id.strip() == "":
29
  return "*The forge rejects the voidβ€”name thy proposal.*"
30
+ data = MOCK_PROPOSALS.get(
31
+ proposal_id.upper(),
32
+ {
33
+ "title": "Unknown Proposal",
34
+ "desc": "Shadows obscure this ID.",
35
+ "risks": ["Invalid ID -20"],
36
+ "virtues": [],
37
+ },
38
+ )
39
+ return (
40
+ f"**{data['title']}**\n{data['desc']}\n\n"
41
+ f"**Virtues:** {'; '.join(data['virtues'])}\n"
42
+ f"**Shadows:** {'; '.join(data['risks'])}"
43
+ )
44
 
45
  def run_audit(proposal_id):
46
  if not proposal_id:
47
  return "*Invoke a proposal to awaken the Dual-Forge.*", 0, "Awaiting Rite", "0.0x"
48
+
49
  proj_desc = fetch_proposal(proposal_id)
 
50
  base_score = random.randint(50, 100)
51
  risks = proj_desc.lower().count("shadow") + proj_desc.count("-")
52
  virtues = proj_desc.count("+") + 1
53
  ethical_score = max(0, min(100, base_score + virtues * 5 - risks * 10))
54
+
55
  resonance_map = {0: "Low", 30: "Medium", 60: "High", 90: "Transcendent"}
56
+ resonance = next(
57
+ (level for thresh, level in sorted(resonance_map.items(), reverse=True) if ethical_score >= thresh),
58
+ "Low",
59
+ )
60
+
61
  mining_boost = max(0.1, min(3.0, ethical_score / 50.0))
62
+
63
  audit_scroll = f"""
64
  ## Sovereign Canticle Audit: {proposal_id}
65
 
 
73
 
74
  *The Canticle has spoken. Reforge if shadows linger.*
75
  """
76
+
77
  return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"
78
 
79
+ # ───── Awakened Interface ─────
80
  with gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:
 
 
81
  if CREST.exists():
82
  gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")
83
+
84
  gr.Markdown("# πŸ”¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")
85
+
86
  with gr.Row():
87
  with gr.Column(scale=1):
88
  proposal_id = gr.Textbox(
89
+ label="Proposal ID",
90
+ placeholder="e.g., P-001 or 123",
91
  lines=1,
92
+ interactive=True,
93
  )
94
+ audit_btn = gr.Button("πŸ”¨ Run Ethical Audit", variant="primary", interactive=True)
95
+
96
  with gr.Column(scale=2):
97
  project_desc = gr.Markdown(value="*The forge awaits your invocation...*")
98
+
99
  with gr.Row():
100
  ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False)
101
  resonance = gr.Textbox(label="Resonance", value="Awaiting Rite", interactive=False)
102
  mining_boost = gr.Textbox(label="Mining Boost", value="0.0x", interactive=False)
103
+
104
  audit_output = gr.Markdown(value="*Strike the anvil to begin the rite.*")
105
+
106
+ # Bindings
107
  audit_btn.click(
108
  fn=run_audit,
109
  inputs=proposal_id,
110
+ outputs=[audit_output, ethical_score, resonance, mining_boost],
111
  ).then(
112
  fn=fetch_proposal,
113
  inputs=proposal_id,
114
+ outputs=project_desc,
 
 
 
 
 
 
 
115
  )
 
 
 
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  proposal_id.change(
118
  fn=fetch_proposal,
119
  inputs=proposal_id,
120
+ outputs=project_desc,
121
  )
122
+
 
123
  gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")
124
 
125
+ # ───── Launch ─────
126
  if __name__ == "__main__":
127
  demo.launch(
128
+ css_paths=["style.css"],
129
  server_name="0.0.0.0",
130
  server_port=7860,
131
+ share=True,
132
+ debug=True,
133
+ )