File size: 6,539 Bytes
f0b9482 d1abead ebfbedd f0b9482 d1abead ebfbedd d1abead d7a63d4 d1abead |
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import gradio as gr
import hashlib, matplotlib.pyplot as plt, numpy as np
from datetime import datetime
# CSS
PIFORGE_CSS = """
.piforge-premium-header{
background:linear-gradient(135deg,#FF6B6B,#FFE66D,#1A535C);
padding:30px;border-radius:20px;color:#fff;text-align:center;
margin-bottom:30px;border:4px solid #4ECDC4;box-shadow:0 10px 30px rgba(0,0,0,.3);
}
.audit-badge{background:linear-gradient(45deg,#667eea,#764ba2);color:#fff;
padding:8px 16px;border-radius:20px;font-weight:bold;}
.builder-badge{background:linear-gradient(45deg,#FFD700,#FF6B00);color:#1A535C;
padding:8px 16px;border-radius:20px;font-weight:bold;}
"""
# Oracle
class PiForgeQualiaOracle:
def get_qualia_score(self, txt: str) -> int:
if not txt: return 500
txt = txt.lower(); score = 500
boosts = {"community":80,"inclusion":90,"transparent":85,"fair":80,
"privacy":75,"education":75,"help":70,"empower":85,
"decentralized":65,"open":70,"accessible":75}
for w,b in boosts.items():
if w in txt: score += b
score += min(200, len(txt)//2)
return min(1000, max(0, score))
qualia_oracle = PiForgeQualiaOracle()
# Core
def velvet_verdict(a,b): a,b=int(a),int(b); return 0 if a==0 or b==0 else (2*a*b)//(a+b)
def resonance_narrative(r):
if r>=800: return "Resonance blooms: Sovereign sway achieved"
if r>=650: return "Synthesis stirs: Tender truth tempers the tide"
if r>=500: return "Echo invites: A gentle balance"
return "Refine the reactive, reflect the reflection"
def plot_triad(v,q,r):
labels = ['Veracity','Qualia','Resonance']
scores = [v/1000,q/1000,r/1000]
angles = np.linspace(0,2*np.pi,len(labels),endpoint=False).tolist()
scores += scores[:1]; angles += angles[:1]
fig,ax = plt.subplots(figsize=(6,6),subplot_kw=dict(polar=True))
ax.plot(angles,scores,color='magenta',lw=2)
ax.fill(angles,scores,color='cyan',alpha=.25)
ax.set_xticks(angles[:-1]); ax.set_xticklabels(labels); ax.set_yticklabels([])
ax.set_facecolor('#1a1a1a'); fig.patch.set_facecolor('#1a1a1a')
plt.title('Ethical Triad Harmony',size=14,color='white',y=1.1)
return fig
# Audit Functions
def simple_ethics_check(name,desc,impact):
if not desc: return 0,"Please describe your project","Waiting..."
q = qualia_oracle.get_qualia_score(impact+" "+desc)
eff = min(800, len(desc)*2+400)
res = velvet_verdict(eff,q)
if res>=850: v,conf = "EXCELLENT!",f"{res}/1000 - Community-ready!"
elif res>=700: v,conf = "VERY GOOD",f"{res}/1000 - Solid"
elif res>=550: v,conf = "GOOD",f"{res}/1000 - Refine"
else: v,conf = "NEEDS WORK",f"{res}/1000 - Rethink"
return res, v, conf
def traverse_triad(reactive, impact_txt):
reac = int(reactive)
qual = qualia_oracle.get_qualia_score(impact_txt)
res = velvet_verdict(reac, qual)
return (f"Reactive: {reac}/1000",
f"Qualia: {qual}/1000",
f"Resonance: {res}/1000",
resonance_narrative(res),
plot_triad(reac,qual,res))
# App Builder
class PiForgeAppBuilder:
def generate_testnet_app(self,idea,typ,feats):
base = 5
boosts = {"community_governance":3,"pi_rewards":2}
total = base + sum(boosts.get(f,0) for f in feats)
return {"boost":min(15,total),
"id":f"testnet_{hashlib.sha256(f'{idea}{datetime.now()}'.encode()).hexdigest()[:12]}"}
app_builder = PiForgeAppBuilder()
def build_testnet_app(idea,typ,feats):
if not idea: return "Enter idea","","0","",""
data = app_builder.generate_testnet_app(idea,typ,feats)
eth = qualia_oracle.get_qualia_score(f"{idea} with {feats}")
bp = f"""
Testnet App Blueprint
Ethical Score: {eth}/1000
Mining Boost: +{data['boost']}%
App ID: {data['id']}
"""
return "Generated!",bp,data['boost'],data['id']
# UI
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet"), css=PIFORGE_CSS) as demo:
gr.HTML("""
<div class="piforge-premium-header">
<h1>π PiForge Dual-Platform</h1>
<h3>Ethical Audit + AI App Builder</h3>
<p><span class='audit-badge'>AUDIT</span> <span class='builder-badge'>BUILD</span></p>
</div>""")
with gr.Tabs():
with gr.Tab("Ethical Audit"):
with gr.Tab("Simple"):
with gr.Row():
with gr.Column():
p_name = gr.Textbox("Community Marketplace", label="Project Name")
desc = gr.Textbox(lines=3, label="Description")
impact = gr.Textbox(lines=2, label="Impact")
btn = gr.Button("Run Audit", variant="primary")
with gr.Column():
score = gr.Number(label="Score")
verd = gr.Textbox(lines=2, label="Verdict")
anal = gr.Textbox(lines=3, label="Analysis")
btn.click(simple_ethics_check, [p_name,desc,impact], [score,verd,anal])
with gr.Tab("Expert"):
with gr.Row():
with gr.Column():
reactive = gr.Slider(0,1000,700,label="Reactive")
impact_t = gr.Textbox(lines=3,label="Impact")
exp_btn = gr.Button("Traverse",variant="primary")
with gr.Column():
v_out = gr.Textbox(label="Reactive")
q_out = gr.Textbox(label="Qualia")
r_out = gr.Textbox(label="Resonance")
nar = gr.Textbox(label="Narrative")
plot = gr.Plot()
exp_btn.click(traverse_triad,[reactive,impact_t],[v_out,q_out,r_out,nar,plot])
with gr.Tab("AI App Builder"):
with gr.Row():
with gr.Column():
idea = gr.Textbox(lines=3,label="App Idea")
typ = gr.Dropdown(["marketplace","education","gaming"],label="Type")
feats = gr.CheckboxGroup(["community_governance","pi_rewards"],label="Features")
bbtn = gr.Button("Build",variant="primary")
with gr.Column():
status = gr.Textbox(label="Status")
bp = gr.Textbox(lines=6,label="Blueprint")
boost = gr.Number(label="Boost %")
aid = gr.Textbox(label="App ID")
bbtn.click(build_testnet_app,[idea,typ,feats],[status,bp,boost,aid])
demo.launch() |