Spaces:
Sleeping
Sleeping
File size: 5,553 Bytes
0a6ec8e 26c1515 efcb4ab 9a594fa 3e7fa5c 26c1515 3e7fa5c 9a594fa 66d535a 0a6ec8e 24ad24b 0a6ec8e 3e7fa5c 66d535a 24ad24b 0a6ec8e efcb4ab 24ad24b efcb4ab 24ad24b efcb4ab 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 9a594fa 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 9a594fa 0a6ec8e 9a594fa 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 9a594fa 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 24ad24b 0a6ec8e 9a594fa 24ad24b 0a6ec8e 24ad24b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# app.py — LimitlessForge V1.4.1: Canticle with True CSS Paths
import gradio as gr
import requests
import random
from pathlib import Path
ASSETS_DIR = Path("assets")
CREST = ASSETS_DIR / "piforge_crest.svg"
# Enhanced Brainstorm Mocks (Seeded from Pi Hackathons)
MOCK_BRAIN_STORM = {
"P-001": {"title": "Global KYC Harmony", "desc": "Decentralized ID via Brainstorm (842 votes).", "votes": 842, "donations": 150.5, "virtues": ["Inclusivity +20", "Sovereignty +15"], "risks": ["Centralization -5"]},
"P-123": {"title": "Mobile Mining Overhaul", "desc": "Q1 2025 Hackathon winner (1294 votes).", "votes": 1294, "donations": 250.0, "virtues": ["Accessibility +25"], "risks": []},
"P-2025-HACK": {"title": "Quantum Governance Forge", "desc": "Ongoing Pi app ethics proposal.", "votes": 500, "donations": 75.0, "virtues": ["Innovation +30"], "risks": ["Complexity -10"]},
}
def fetch_live_brainstorm(proposal_id, token=""):
if not proposal_id:
return "*The forge rejects the void—name thy proposal.*"
# Live Rite: Pi API for Brainstorm (App as Proposal)
if token:
headers = {"Authorization": f"Bearer {token}"}
try:
url = f"https://api.minepi.com/v2/apps/{proposal_id.upper()}"
r = requests.get(url, headers=headers, timeout=10)
if r.status_code == 200:
data = r.json()
title = data.get('name', 'Live Proposal')
desc = data.get('description', 'From Pi Chain.')
votes = data.get('votes', 0)
donations = data.get('donations', 0.0)
virtues = data.get('virtues', ["Live +10"])
risks = data.get('risks', ["No shadows"])
return f"**{title}** (Votes: {votes} | Donations: {donations} Pi)\n{desc}\n\n**Virtues:** {'; '.join(virtues)}\n**Shadows:** {'; '.join(risks)}"
except Exception as e:
return f"*Chain shadowed: {str(e)}. Echoing Brainstorm.*"
# Fallback: Hackathon Echo
d = MOCK_BRAIN_STORM.get(proposal_id.upper(),
{"title": "Echo Proposal", "desc": "From Pi 2025 archives.", "votes": random.randint(100, 2000), "donations": random.uniform(50, 300), "virtues": ["Community +15"], "risks": ["Unverified -10"]})
return f"**{d['title']}** (Votes: {d['votes']} | Donations: {d['donations']:.1f} Pi)\n{d['desc']}\n\n**Virtues:** {'; '.join(d['virtues'])}\n**Shadows:** {'; '.join(d['risks'])}"
def canticle_audit(proposal_id, token):
if not proposal_id:
return "*Invoke to awaken.*", 0, "Awaiting", "0.0x"
echo = fetch_live_brainstorm(proposal_id, token)
virtues = echo.count("+")
risks = echo.count("-")
votes_bonus = int(''.join(filter(str.isdigit, echo.split("Votes:")[-1].split()[0]))) / 100 if "Votes:" in echo else 0
donations_bonus = float(''.join(filter(str.isdigit, str(echo.split("Donations:")[-1].split()[0].replace('.', ''))))) / 100 if "Donations:" in echo else 0
base = random.randint(60, 95)
score = max(0, min(100, base + virtues * 8 - risks * 12 + votes_bonus * 3 + donations_bonus * 5))
resonance_map = {0: "Low", 40: "Medium", 70: "High", 90: "Transcendent"}
resonance = next((level for thresh, level in sorted(resonance_map.items(), reverse=True) if score >= thresh), "Low")
boost = max(0.1, min(3.0, score / 40 + votes_bonus / 2 + donations_bonus))
scroll = f"""
## Canticle Audit: {proposal_id}
**Echo:** {echo}
**Verdict:**
- Scan: {virtues} virtues, {risks} shadows.
- Resonance: {resonance} (Score: {score} | Votes +{votes_bonus:.1f} | Donations +{donations_bonus:.1f} Pi).
**Boost:** {boost:.2f}x
*Brainstorm communes. Reforge.*
"""
return scroll, score, resonance, f"{boost:.2f}x"
# Interface: Veil in Blocks
with gr.Blocks(
title="LimitlessForge V1.4.1",
css_paths=["style.css"] # ← FIXED: Paths in Blocks
) as demo:
if CREST.exists():
gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest'/></div>")
gr.Markdown("# 🔨 LimitlessForge V1.4.1\n## Live Pi Brainstorm Auditor")
with gr.Row():
with gr.Column(scale=1):
proposal_id = gr.Textbox(label="Proposal ID", placeholder="e.g., P-001", interactive=True)
pi_token = gr.Textbox(label="Pi Token (Optional)", type="password")
audit_btn = gr.Button("🔥 Strike Canticle", variant="primary")
with gr.Column(scale=2):
project_echo = gr.Markdown("*Invoke a proposal...*")
with gr.Row():
ethical_score = gr.Number(label="Ethical Score", interactive=False)
resonance = gr.Textbox(label="Resonance", interactive=False)
mining_boost = gr.Textbox(label="Mining Boost", interactive=False)
audit_scroll = gr.Markdown("*The ledger awaits.*")
audit_btn.click(
fn=canticle_audit,
inputs=[proposal_id, pi_token],
outputs=[audit_scroll, ethical_score, resonance, mining_boost]
).then(
fn=fetch_live_brainstorm,
inputs=[proposal_id, pi_token],
outputs=project_echo
)
proposal_id.change(
fn=fetch_live_brainstorm,
inputs=[proposal_id, pi_token],
outputs=project_echo
)
gr.HTML("<div class='footer'><p class='footer-text'>Forged with Pi's Brainstorm. Eternal.</p></div>")
if __name__ == "__main__":
demo.launch( # ← FIXED: Clean launch, no css_paths here
server_name="0.0.0.0",
server_port=7860,
debug=True
) |