onenoly11 commited on
Commit
0603655
Β·
verified Β·
1 Parent(s): 3e7fa5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -16
app.py CHANGED
@@ -1,40 +1,118 @@
1
- # app.py β€” PiForge Ethical Dual-Forge V1.2: Fully Interactive, HF Spaces Ready
2
  import gradio as gr
3
- import random # For mock Pi API resonance
4
  from pathlib import Path
5
 
6
- # ───── Assets (Optional: Add to /assets/ for Neon Flair) ─────
7
  ASSETS_DIR = Path("assets")
8
- CREST = ASSETS_DIR / "piforge_crest.svg" # Hammer sigil
9
 
10
- # ───── Mock Pi Proposal Data (Replace with Real API Later) ─────
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"]},
14
- # Add more or fetch via requests.get("https://api.pi.network/proposals/{id}")
15
  }
16
 
17
- # ───── Core Canticle Functions ──────────────────────────────
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(), {"title": "Unknown Proposal", "desc": "Shadows obscure this ID.", "risks": ["Invalid ID -20"], "virtues": []})
 
22
  return f"**{data['title']}**\n{data['desc']}\n\n**Virtues:** {'; '.join(data['virtues'])}\n**Shadows:** {'; '.join(data['risks'])}"
23
 
24
  def run_audit(proposal_id):
25
  if not proposal_id:
26
- return "Error: No proposal invoked.", "Error", "Error", "Error"
27
 
28
  proj_desc = fetch_proposal(proposal_id)
29
- # Dual-Forge Logic: Ethical Score (0-100), Resonance (Low/Med/High/Transcendent), Boost (0.1x-3.0x)
30
- base_score = random.randint(50, 100) # Mock; tune with real ethics weights
31
- risks = len(proj_desc.count("shadow") + proj_desc.count("-")) # Simple parse
32
- virtues = len(proj_desc.count("+")) + 1
33
  ethical_score = max(0, min(100, base_score + virtues * 5 - risks * 10))
34
 
35
  resonance_map = {0: "Low", 30: "Medium", 60: "High", 90: "Transcendent"}
36
- resonance = next((level for thresh, level in sorted(resonance_map.items()) if ethical_score >= thresh), "Low")
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  mining_boost = max(0.1, min(3.0, ethical_score / 50.0)) # Scaled reward
39
 
40
  audit_scroll = f"""
 
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
+
44
+ **Project Echo:** {proj_desc}
45
+
46
+ **Dual-Forge Verdict:**
47
+ - Purity Scan: {virtues} virtues forged, {risks} shadows tempered.
48
+ - Resonance with Pi's Vision: {resonance} (Threshold: {ethical_score}).
49
+
50
+ **Mining Boost Granted:** {mining_boost:.1f}x β€” Flow amplified for the worthy.
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"""