|
|
import gradio as gr |
|
|
import hashlib, matplotlib.pyplot as plt, numpy as np |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
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;} |
|
|
""" |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
|
|
|
|
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'] |
|
|
|
|
|
|
|
|
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() |