Spaces:
Sleeping
Sleeping
| # 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 | |
| ) |