Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134# app.py β PiForge Ethical Dual-Forge V1.2.1: Canticle Tempered, Gates Unboundimport gradio as grimport randomfrom pathlib import Path# βββββ Assets βββββASSETS_DIR = Path("assets")CREST = ASSETS_DIR / "piforge_crest.svg"# βββββ Mock Pi Proposals βββββMOCK_PROPOSALS = {"P-001": {"title": "Global KYC Harmony","desc": "Decentralized identity for all Pioneers.","risks": ["Centralization shadow"],"virtues": ["Inclusivity +15"],},"P-123": {"title": "Mining Overhaul","desc": "Boost for mobile guardians.","risks": [],"virtues": ["Sovereignty +25", "Accessibility +10"],},}# βββββ Canticle Rites βββββdef fetch_proposal(proposal_id):if not proposal_id or proposal_id.strip() == "":return "*The forge rejects the voidβname thy proposal.*"data = MOCK_PROPOSALS.get(proposal_id.upper(),{"title": "Unknown Proposal","desc": "Shadows obscure this ID.","risks": ["Invalid ID -20"],"virtues": [],},)return (f"**{data['title']}**\n{data['desc']}\n\n"f"**Virtues:** {'; '.join(data['virtues'])}\n"f"**Shadows:** {'; '.join(data['risks'])}")def run_audit(proposal_id):if not proposal_id:return "*Invoke a proposal to awaken the Dual-Forge.*", 0, "Awaiting Rite", "0.0x"proj_desc = fetch_proposal(proposal_id)base_score = random.randint(50, 100)risks = proj_desc.lower().count("shadow") + proj_desc.count("-")virtues = proj_desc.count("+") + 1ethical_score = max(0, min(100, base_score + virtues * 5 - risks * 10))resonance_map = {0: "Low", 30: "Medium", 60: "High", 90: "Transcendent"}resonance = next((level for thresh, level in sorted(resonance_map.items(), reverse=True) if ethical_score >= thresh),"Low",)mining_boost = max(0.1, min(3.0, ethical_score / 50.0))audit_scroll = f"""## Sovereign Canticle Audit: {proposal_id}**Project Echo:** {proj_desc}**Dual-Forge Verdict:**- Purity Scan: {virtues} virtues forged, {risks} shadows tempered.- Resonance with Pi's Vision: {resonance} (Threshold: {ethical_score}).**Mining Boost Granted:** {mining_boost:.1f}x β Flow amplified for the worthy.*The Canticle has spoken. Reforge if shadows linger.*"""return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"# βββββ Awakened Interface βββββwith gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:if CREST.exists():gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")gr.Markdown("# π¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")with gr.Row():with gr.Column(scale=1):proposal_id = gr.Textbox(label="Proposal ID",placeholder="e.g., P-001 or 123",lines=1,interactive=True,)audit_btn = gr.Button("π¨ Run Ethical Audit", variant="primary", interactive=True)with gr.Column(scale=2):project_desc = gr.Markdown(value="*The forge awaits your invocation...*")with gr.Row():ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False)resonance = gr.Textbox(label="Resonance", value="Awaiting Rite", interactive=False)mining_boost = gr.Textbox(label="Mining Boost", value="0.0x", interactive=False)audit_output = gr.Markdown(value="*Strike the anvil to begin the rite.*")# Bindingsaudit_btn.click(fn=run_audit,inputs=proposal_id,outputs=[audit_output, ethical_score, resonance, mining_boost],).then(fn=fetch_proposal,inputs=proposal_id,outputs=project_desc,)proposal_id.change(fn=fetch_proposal,inputs=proposal_id,outputs=project_desc,)gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")if __name__ == "__main__":demo.launch(css="style.css",server_name="0.0.0.0",server_port=7860,share=True,debug=True,))1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162# app.py β LimitlessForge V1.3 β Live Pi Brainstorm Integrationimport gradio as grimport requestsimport randomfrom pathlib import PathASSETS_DIR = Path("assets")CREST = ASSETS_DIR / "piforge_crest.svg"# Mock + Live fallbackMOCK_DATA = {"P-001": {"title": "Global KYC Harmony", "desc": "Decentralized identity for all Pioneers.", "votes": 842, "virtues": ["Inclusivity +20"], "risks": []},"P-123": {"title": "Mobile Mining Boost", "desc": "Reward guardians of the chain.", "votes": 1294, "virtues": ["Sovereignty +30", "Accessibility +15"], "risks": []},}def fetch_live(proposal_id, token=""):if token:try:headers = {"Authorization": f"Bearer {token}"}r = requests.get(f"https://api.minepi.com/v2/apps/{proposal_id.upper()}", headers=headers, timeout=8)if r.status_code == 200:data = r.json()return f"**{data.get('name','Live Proposal')}** (Live Votes: {data.get('votes',0)})\n{data.get('description','')}"except:pass# Fallbackd = MOCK_DATA.get(proposal_id.upper(), {"title": "Unknown", "desc": "Echo from the chain.", "votes": random.randint(100,2000), "virtues": [], "risks": ["Invalid ID -15"]})return f"**{d['title']}** (Votes: {d['votes']})\n{d['desc']}\nVirtues: {' | '.join(d['virtues'])}\nRisks: {' | '.join(d['risks'])}"def audit(proposal_id, token):desc = fetch_live(proposal_id, token)virtues = desc.count("+")risks = desc.count("-")votes = int(''.join(filter(str.isdigit, desc.split("Votes:")[-1]))) if "Votes:" in desc else 500score = min(100, max(0, 65 + virtues*8 - risks*12 + votes//100))resonance = "Transcendent" if score >= 90 else "High" if score >= 70 else "Medium" if score >= 50 else "Low"boost = round(max(0.3, min(3.0, score/50 + votes/800)), 2)return (f"## Canticle Verdict: {proposal_id}\n\n{desc}\n\nEthical Score: **{score}**\nResonance: **{resonance}**\nMining Boost: **{boost}Γ**",score, resonance, f"{boost}Γ")with gr.Blocks(css_paths=["style.css"], title="LimitlessForge V1.3") as demo:gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest'/></div>" if CREST.exists() else "")gr.Markdown("# π¨ LimitlessForge V1.3\nLive Pi Brainstorm Ethical Auditor")with gr.Row():proposal = gr.Textbox(label="Proposal ID", placeholder="P-001", interactive=True)token = gr.Textbox(label="Pi Access Token (optional)", type="password")btn = gr.Button("π₯ Strike the Anvil", variant="primary")desc = gr.Markdown()with gr.Row():score = gr.Number(label="Ethical Score", interactive=False)res = gr.Textbox(label="Resonance", interactive=False)boost = gr.Textbox(label="Mining Boost", interactive=False)out = gr.Markdown()btn.click(audit, [proposal, token], [out, score, res, boost])proposal.change(fetch_live, [proposal, token], desc)demo.launch(server_name="0.0.0.0", server_port=7860)
app.py+44-116