Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,134 +1,62 @@
|
|
| 1 |
-
# app.py β
|
| 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 |
-
#
|
| 11 |
-
|
| 12 |
-
"P-001": {
|
| 13 |
-
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
return (
|
| 40 |
-
f"
|
| 41 |
-
f"
|
| 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 |
-
|
| 62 |
-
|
| 63 |
-
|
| 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 |
-
|
| 88 |
-
|
| 89 |
-
|
| 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 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
-
|
|
|
|
| 105 |
|
| 106 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|