onenoly11 commited on
Commit
efcb4ab
Β·
verified Β·
1 Parent(s): 2408b3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -116
app.py CHANGED
@@ -1,134 +1,62 @@
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
-
66
- **Project Echo:** {proj_desc}
67
-
68
- **Dual-Forge Verdict:**
69
- - Purity Scan: {virtues} virtues forged, {risks} shadows tempered.
70
- - Resonance with Pi's Vision: {resonance} (Threshold: {ethical_score}).
71
-
72
- **Mining Boost Granted:** {mining_boost:.1f}x β€” Flow amplified for the worthy.
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
- if __name__ == "__main__":
126
- demo.launch(
127
- css="style.css",
128
- server_name="0.0.0.0",
129
- server_port=7860,
130
- share=True,
131
- debug=True,
132
- )
133
-
134
- )
 
1
+ # app.py β€” LimitlessForge V1.3 – Live Pi Brainstorm Integration
2
  import gradio as gr
3
+ import requests
4
  import random
5
  from pathlib import Path
6
 
 
7
  ASSETS_DIR = Path("assets")
8
  CREST = ASSETS_DIR / "piforge_crest.svg"
9
 
10
+ # Mock + Live fallback
11
+ MOCK_DATA = {
12
+ "P-001": {"title": "Global KYC Harmony", "desc": "Decentralized identity for all Pioneers.", "votes": 842, "virtues": ["Inclusivity +20"], "risks": []},
13
+ "P-123": {"title": "Mobile Mining Boost", "desc": "Reward guardians of the chain.", "votes": 1294, "virtues": ["Sovereignty +30", "Accessibility +15"], "risks": []},
 
 
 
 
 
 
 
 
 
 
14
  }
15
 
16
+ def fetch_live(proposal_id, token=""):
17
+ if token:
18
+ try:
19
+ headers = {"Authorization": f"Bearer {token}"}
20
+ r = requests.get(f"https://api.minepi.com/v2/apps/{proposal_id.upper()}", headers=headers, timeout=8)
21
+ if r.status_code == 200:
22
+ data = r.json()
23
+ return f"**{data.get('name','Live Proposal')}** (Live Votes: {data.get('votes',0)})\n{data.get('description','')}"
24
+ except:
25
+ pass
26
+ # Fallback
27
+ d = MOCK_DATA.get(proposal_id.upper(), {"title": "Unknown", "desc": "Echo from the chain.", "votes": random.randint(100,2000), "virtues": [], "risks": ["Invalid ID -15"]})
28
+ return f"**{d['title']}** (Votes: {d['votes']})\n{d['desc']}\nVirtues: {' | '.join(d['virtues'])}\nRisks: {' | '.join(d['risks'])}"
29
+
30
+ def audit(proposal_id, token):
31
+ desc = fetch_live(proposal_id, token)
32
+ virtues = desc.count("+")
33
+ risks = desc.count("-")
34
+ votes = int(''.join(filter(str.isdigit, desc.split("Votes:")[-1]))) if "Votes:" in desc else 500
35
+ score = min(100, max(0, 65 + virtues*8 - risks*12 + votes//100))
36
+ resonance = "Transcendent" if score >= 90 else "High" if score >= 70 else "Medium" if score >= 50 else "Low"
37
+ boost = round(max(0.3, min(3.0, score/50 + votes/800)), 2)
38
  return (
39
+ f"## Canticle Verdict: {proposal_id}\n\n{desc}\n\nEthical Score: **{score}**\nResonance: **{resonance}**\nMining Boost: **{boost}Γ—**",
40
+ score, resonance, f"{boost}Γ—"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  )
42
 
43
+ with gr.Blocks(css_paths=["style.css"], title="LimitlessForge V1.3") as demo:
44
+ gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest'/></div>" if CREST.exists() else "")
45
+ gr.Markdown("# πŸ”¨ LimitlessForge V1.3\nLive Pi Brainstorm Ethical Auditor")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  with gr.Row():
48
+ proposal = gr.Textbox(label="Proposal ID", placeholder="P-001", interactive=True)
49
+ token = gr.Textbox(label="Pi Access Token (optional)", type="password")
50
+ btn = gr.Button("πŸ”₯ Strike the Anvil", variant="primary")
 
 
 
 
 
 
 
 
51
 
52
+ desc = gr.Markdown()
53
  with gr.Row():
54
+ score = gr.Number(label="Ethical Score", interactive=False)
55
+ res = gr.Textbox(label="Resonance", interactive=False)
56
+ boost = gr.Textbox(label="Mining Boost", interactive=False)
57
+ out = gr.Markdown()
58
 
59
+ btn.click(audit, [proposal, token], [out, score, res, boost])
60
+ proposal.change(fetch_live, [proposal, token], desc)
61
 
62
+ demo.launch(server_name="0.0.0.0", server_port=7860)