Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,65 @@
|
|
| 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 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# βββββ Canticle Rites
|
| 18 |
def fetch_proposal(proposal_id):
|
| 19 |
if not proposal_id or proposal_id.strip() == "":
|
| 20 |
return "*The forge rejects the voidβname thy proposal.*"
|
| 21 |
-
data = MOCK_PROPOSALS.get(
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def run_audit(proposal_id):
|
| 26 |
if not proposal_id:
|
| 27 |
return "*Invoke a proposal to awaken the Dual-Forge.*", 0, "Awaiting Rite", "0.0x"
|
| 28 |
-
|
| 29 |
proj_desc = fetch_proposal(proposal_id)
|
| 30 |
-
# Dual-Forge: Score (0-100), Resonance, Boost
|
| 31 |
base_score = random.randint(50, 100)
|
| 32 |
risks = proj_desc.lower().count("shadow") + proj_desc.count("-")
|
| 33 |
virtues = proj_desc.count("+") + 1
|
| 34 |
ethical_score = max(0, min(100, base_score + virtues * 5 - risks * 10))
|
| 35 |
-
|
| 36 |
resonance_map = {0: "Low", 30: "Medium", 60: "High", 90: "Transcendent"}
|
| 37 |
-
resonance = next(
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
mining_boost = max(0.1, min(3.0, ethical_score / 50.0))
|
| 40 |
-
|
| 41 |
audit_scroll = f"""
|
| 42 |
## Sovereign Canticle Audit: {proposal_id}
|
| 43 |
|
|
@@ -51,143 +73,61 @@ def run_audit(proposal_id):
|
|
| 51 |
|
| 52 |
*The Canticle has spoken. Reforge if shadows linger.*
|
| 53 |
"""
|
| 54 |
-
|
| 55 |
return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"
|
| 56 |
|
| 57 |
-
# βββββ Awakened Interface
|
| 58 |
with gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:
|
| 59 |
-
|
| 60 |
-
# Neon Banner
|
| 61 |
if CREST.exists():
|
| 62 |
gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")
|
| 63 |
-
|
| 64 |
gr.Markdown("# π¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")
|
| 65 |
-
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column(scale=1):
|
| 68 |
proposal_id = gr.Textbox(
|
| 69 |
-
label="Proposal ID",
|
| 70 |
-
placeholder="e.g., P-001 or 123",
|
| 71 |
lines=1,
|
| 72 |
-
interactive=True
|
| 73 |
)
|
| 74 |
-
audit_btn = gr.Button("π¨ Run Ethical Audit", variant="primary", interactive=True)
|
| 75 |
-
|
| 76 |
with gr.Column(scale=2):
|
| 77 |
project_desc = gr.Markdown(value="*The forge awaits your invocation...*")
|
| 78 |
-
|
| 79 |
with gr.Row():
|
| 80 |
ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False)
|
| 81 |
resonance = gr.Textbox(label="Resonance", value="Awaiting Rite", interactive=False)
|
| 82 |
mining_boost = gr.Textbox(label="Mining Boost", value="0.0x", interactive=False)
|
| 83 |
-
|
| 84 |
audit_output = gr.Markdown(value="*Strike the anvil to begin the rite.*")
|
| 85 |
-
|
| 86 |
-
#
|
| 87 |
audit_btn.click(
|
| 88 |
fn=run_audit,
|
| 89 |
inputs=proposal_id,
|
| 90 |
-
outputs=[audit_output, ethical_score, resonance, mining_boost]
|
| 91 |
).then(
|
| 92 |
fn=fetch_proposal,
|
| 93 |
inputs=proposal_id,
|
| 94 |
-
outputs=project_desc
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
# Instant Echo: ID Change β Description
|
| 98 |
-
proposal_id.change(
|
| 99 |
-
fn=fetch_proposal,
|
| 100 |
-
inputs=proposal_id,
|
| 101 |
-
outputs=project_desc
|
| 102 |
)
|
| 103 |
-
|
| 104 |
-
# Hymnal Footer
|
| 105 |
-
gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")
|
| 106 |
|
| 107 |
-
# βββββ Launch: Canticle's Seal (css_paths for Gradio 5.x+) βββββ
|
| 108 |
-
if __name__ == "__main__":
|
| 109 |
-
demo.launch(
|
| 110 |
-
css_paths=["style.css"], # Neon Veil: File Path Accepted
|
| 111 |
-
server_name="0.0.0.0",
|
| 112 |
-
server_port=7860,
|
| 113 |
-
share=True, # Local Share (HF Public Handles)
|
| 114 |
-
debug=True # Log Whispers for Refinement
|
| 115 |
-
)
|
| 116 |
-
mining_boost = max(0.1, min(3.0, ethical_score / 50.0)) # Scaled reward
|
| 117 |
-
|
| 118 |
-
audit_scroll = f"""
|
| 119 |
-
## Sovereign Canticle Audit: {proposal_id}
|
| 120 |
-
|
| 121 |
-
**Project Echo:** {proj_desc}
|
| 122 |
-
|
| 123 |
-
**Dual-Forge Verdict:**
|
| 124 |
-
- Purity Scan: {virtues} virtues forged, {risks} shadows tempered.
|
| 125 |
-
- Resonance with Pi's Vision: {resonance} (Threshold: {resonance_map.get(resonance, 'Unknown')}).
|
| 126 |
-
|
| 127 |
-
**Mining Boost Granted:** {mining_boost:.1f}x β Flow amplified for the worthy.
|
| 128 |
-
|
| 129 |
-
*The Canticle has spoken. Reforge if shadows linger.*
|
| 130 |
-
"""
|
| 131 |
-
|
| 132 |
-
return audit_scroll, ethical_score, resonance, f"{mining_boost:.1f}x"
|
| 133 |
-
|
| 134 |
-
# βββββ Gradio Interface: Awakened Gates ββββββββββββββββββββ
|
| 135 |
-
with gr.Blocks(title="PiForge Ethical Dual-Forge V1.2") as demo:
|
| 136 |
-
|
| 137 |
-
# Banner: Neon Crest
|
| 138 |
-
if CREST.exists():
|
| 139 |
-
gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest' alt='PiForge Sigil'/></div>")
|
| 140 |
-
|
| 141 |
-
gr.Markdown("# π¨ PiForge Ethical Dual-Forge V1.2\n## Sovereign Canticle Powered Ethical Audit System")
|
| 142 |
-
|
| 143 |
-
with gr.Row(): # Layout Balance: Inputs Side-by-Side
|
| 144 |
-
with gr.Column(scale=1):
|
| 145 |
-
proposal_id = gr.Textbox(
|
| 146 |
-
label="Proposal ID",
|
| 147 |
-
placeholder="Enter Pi Proposal ID (e.g., P-001 or 123)",
|
| 148 |
-
lines=1,
|
| 149 |
-
interactive=True # β KEY: Forces Input Awakening
|
| 150 |
-
)
|
| 151 |
-
audit_btn = gr.Button("Run Ethical Audit", variant="primary", interactive=True) # β Bound & Awake
|
| 152 |
-
|
| 153 |
-
with gr.Column(scale=2):
|
| 154 |
-
project_desc = gr.Markdown(value="The forge awaits your invocation...") # Dynamic Output
|
| 155 |
-
|
| 156 |
-
with gr.Row():
|
| 157 |
-
ethical_score = gr.Number(label="Ethical Score", value=0, interactive=False) # Output-Only
|
| 158 |
-
resonance = gr.Textbox(label="Resonance", value="Error", interactive=False) # Output-Only
|
| 159 |
-
mining_boost = gr.Textbox(label="Mining Boost", value="Error", interactive=False) # Output-Only
|
| 160 |
-
|
| 161 |
-
# Full Audit Scroll
|
| 162 |
-
audit_output = gr.Markdown(value="Strike the anvil to begin the rite.")
|
| 163 |
-
|
| 164 |
-
# βββββ Event Bindings: The Dataflow Awakening βββββββββββββ
|
| 165 |
-
audit_btn.click(
|
| 166 |
-
fn=run_audit,
|
| 167 |
-
inputs=proposal_id,
|
| 168 |
-
outputs=[audit_output, ethical_score, resonance, mining_boost]
|
| 169 |
-
).then( # Chain: Update Description After Audit
|
| 170 |
-
fn=fetch_proposal,
|
| 171 |
-
inputs=proposal_id,
|
| 172 |
-
outputs=project_desc
|
| 173 |
-
)
|
| 174 |
-
|
| 175 |
-
# Auto-Update Description on ID Change (Bonus Interactivity)
|
| 176 |
proposal_id.change(
|
| 177 |
fn=fetch_proposal,
|
| 178 |
inputs=proposal_id,
|
| 179 |
-
outputs=project_desc
|
| 180 |
)
|
| 181 |
-
|
| 182 |
-
# Footer Hymn
|
| 183 |
gr.HTML("<div class='footer'><p class='footer-text'>Forged in ethical fire. Powered by Pi's sovereign will.</p></div>")
|
| 184 |
|
| 185 |
-
# βββββ Launch
|
| 186 |
if __name__ == "__main__":
|
| 187 |
demo.launch(
|
| 188 |
-
|
| 189 |
server_name="0.0.0.0",
|
| 190 |
server_port=7860,
|
| 191 |
-
share=True,
|
| 192 |
-
debug=True
|
| 193 |
-
)
|
|
|
|
| 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 |
|
|
|
|
| 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 |
+
# βββββ Launch βββββ
|
| 126 |
if __name__ == "__main__":
|
| 127 |
demo.launch(
|
| 128 |
+
css_paths=["style.css"],
|
| 129 |
server_name="0.0.0.0",
|
| 130 |
server_port=7860,
|
| 131 |
+
share=True,
|
| 132 |
+
debug=True,
|
| 133 |
+
)
|