onenoly11 commited on
Commit
0a6ec8e
·
verified ·
1 Parent(s): 24ad24b

Update app.py

Browse files

git add . && git commit -m "V1.4.1 – CSS paths tempered in Blocks" && git push

Files changed (1) hide show
  1. app.py +47 -48
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py — LimitlessForge V1.4: Live Pi Brainstorm Communion
2
  import gradio as gr
3
  import requests
4
  import random
@@ -7,99 +7,99 @@ from pathlib import Path
7
  ASSETS_DIR = Path("assets")
8
  CREST = ASSETS_DIR / "piforge_crest.svg"
9
 
10
- # Enhanced Mock (Seeded from Real Hackathon Proposals)
11
  MOCK_BRAIN_STORM = {
12
- "P-001": {"title": "Global KYC Harmony", "desc": "Decentralized ID via Brainstorm vote (842 Pioneers).", "votes": 842, "donations": 150.5, "virtues": ["Inclusivity +20", "Sovereignty +15"], "risks": ["Centralization -5"]},
13
- "P-123": {"title": "Mobile Mining Overhaul", "desc": "Hackathon winner: Mobile boosts (1294 votes).", "votes": 1294, "donations": 250.0, "virtues": ["Accessibility +25"], "risks": []},
14
- "P-2025-HACK": {"title": "Quantum Governance Forge", "desc": "Ongoing 2025 proposal: AI ethics for Pi apps.", "votes": 500, "donations": 75.0, "virtues": ["Innovation +30"], "risks": ["Complexity -10"]},
15
  }
16
 
17
  def fetch_live_brainstorm(proposal_id, token=""):
18
  if not proposal_id:
19
  return "*The forge rejects the void—name thy proposal.*"
20
 
21
- # Live Pi API Rite: Authenticated Brainstorm Query
22
  if token:
23
  headers = {"Authorization": f"Bearer {token}"}
24
  try:
25
- # Query proposal as app (Brainstorm hub)
26
  url = f"https://api.minepi.com/v2/apps/{proposal_id.upper()}"
27
  r = requests.get(url, headers=headers, timeout=10)
28
  if r.status_code == 200:
29
  data = r.json()
30
- title = data.get('name', 'Live Brainstorm Proposal')
31
- desc = data.get('description', 'Fetched from Pi Chain.')
32
  votes = data.get('votes', 0)
33
- donations = data.get('donations', 0.0) # Pi support
34
- virtues = data.get('virtues', ["Live Alignment +10"])
35
- risks = data.get('risks', ["No shadows in the chain"])
36
  return f"**{title}** (Votes: {votes} | Donations: {donations} Pi)\n{desc}\n\n**Virtues:** {'; '.join(virtues)}\n**Shadows:** {'; '.join(risks)}"
37
  except Exception as e:
38
- return f"*Chain whisper shadowed: {str(e)}. Falling to Brainstorm echo.*"
39
 
40
- # Sovereign Fallback: Hackathon-Seeded Mock
41
  d = MOCK_BRAIN_STORM.get(proposal_id.upper(),
42
- {"title": "Echo Proposal", "desc": "From Pi's 2025 Hackathon archives.", "votes": random.randint(100, 2000), "donations": random.uniform(50, 300), "virtues": ["Community +15"], "risks": ["Unverified -10"]})
43
- return f"**{d['title']}** (Brainstorm Votes: {d['votes']} | Donations: {d['donations']:.1f} Pi)\n{d['desc']}\n\n**Virtues:** {'; '.join(d['virtues'])}\n**Shadows:** {'; '.join(d['risks'])}"
44
 
45
  def canticle_audit(proposal_id, token):
46
  if not proposal_id:
47
- return "*Invoke to awaken the Dual-Forge.*", 0, "Awaiting Rite", "0.0x"
48
 
49
- proj_echo = fetch_live_brainstorm(proposal_id, token)
50
- # Live Canticle: Parse + Chain Metrics
51
- virtues = proj_echo.count("+")
52
- risks = proj_echo.count("-")
53
- votes_bonus = int(''.join(filter(str.isdigit, proj_echo.split("Votes:")[-1].split()[0]))) / 100 if "Votes:" in proj_echo else 0
54
- donations_bonus = float(''.join(filter(str.isdigit, str(proj_echo.split("Donations:")[-1].split()[0]))) ) / 100 if "Donations:" in proj_echo else 0
55
- base_score = random.randint(60, 95)
56
- ethical_score = max(0, min(100, base_score + virtues * 8 - risks * 12 + votes_bonus * 3 + donations_bonus * 5))
57
 
58
  resonance_map = {0: "Low", 40: "Medium", 70: "High", 90: "Transcendent"}
59
- resonance = next((level for thresh, level in sorted(resonance_map.items(), reverse=True) if ethical_score >= thresh), "Low")
60
 
61
- mining_boost = max(0.1, min(3.0, ethical_score / 40 + votes_bonus / 2 + donations_bonus))
62
 
63
- audit_scroll = f"""
64
- ## Sovereign Canticle Audit: {proposal_id} (Live Brainstorm Fetch)
65
 
66
- **Project Echo:** {proj_echo}
67
 
68
- **Dual-Forge Verdict:**
69
- - Purity Scan: {virtues} virtues forged, {risks} shadows tempered.
70
- - Resonance with Pi's Vision: {resonance} (Score: {ethical_score} | Votes Bonus: +{votes_bonus:.1f} | Donations: +{donations_bonus:.1f} Pi).
71
 
72
- **Mining Boost Granted:** {mining_boost:.2f}x — Amplified by Pioneer will and chain donations.
73
 
74
- *The Canticle communes with Brainstorm. Reforge the worthy.*
75
  """
76
 
77
- return audit_scroll, ethical_score, resonance, f"{mining_boost:.2f}x"
78
 
79
- # Awakened Interface
80
- with gr.Blocks(title="LimitlessForge V1.4 – Live Brainstorm Edition") as demo:
 
 
 
81
  if CREST.exists():
82
  gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest'/></div>")
83
 
84
- gr.Markdown("# 🔨 LimitlessForge V1.4\n## Sovereign Canticle: Live Pi Brainstorm Auditor")
85
 
86
  with gr.Row():
87
  with gr.Column(scale=1):
88
- proposal_id = gr.Textbox(label="Brainstorm Proposal ID", placeholder="e.g., P-001 or Hack-2025", interactive=True)
89
- pi_token = gr.Textbox(label="Pi Access Token (for Live Fetch)", type="password")
90
- audit_btn = gr.Button("🔥 Strike the Canticle", variant="primary")
91
 
92
  with gr.Column(scale=2):
93
- project_echo = gr.Markdown(value="*Invoke a Brainstorm proposal to commune with the chain...*")
94
 
95
  with gr.Row():
96
  ethical_score = gr.Number(label="Ethical Score", interactive=False)
97
  resonance = gr.Textbox(label="Resonance", interactive=False)
98
  mining_boost = gr.Textbox(label="Mining Boost", interactive=False)
99
 
100
- audit_scroll = gr.Markdown(value="*The live ledger awaits your judgment.*")
101
 
102
- # Bindings: Flow Awakens
103
  audit_btn.click(
104
  fn=canticle_audit,
105
  inputs=[proposal_id, pi_token],
@@ -116,11 +116,10 @@ with gr.Blocks(title="LimitlessForge V1.4 – Live Brainstorm Edition") as demo:
116
  outputs=project_echo
117
  )
118
 
119
- gr.HTML("<div class='footer'><p class='footer-text'>Forged with Pi's live Brainstorm APIs. Eternal sovereignty.</p></div>")
120
 
121
  if __name__ == "__main__":
122
- demo.launch(
123
- css_paths=["style.css"],
124
  server_name="0.0.0.0",
125
  server_port=7860,
126
  debug=True
 
1
+ # app.py — LimitlessForge V1.4.1: Canticle with True CSS Paths
2
  import gradio as gr
3
  import requests
4
  import random
 
7
  ASSETS_DIR = Path("assets")
8
  CREST = ASSETS_DIR / "piforge_crest.svg"
9
 
10
+ # Enhanced Brainstorm Mocks (Seeded from Pi Hackathons)
11
  MOCK_BRAIN_STORM = {
12
+ "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"]},
13
+ "P-123": {"title": "Mobile Mining Overhaul", "desc": "Q1 2025 Hackathon winner (1294 votes).", "votes": 1294, "donations": 250.0, "virtues": ["Accessibility +25"], "risks": []},
14
+ "P-2025-HACK": {"title": "Quantum Governance Forge", "desc": "Ongoing Pi app ethics proposal.", "votes": 500, "donations": 75.0, "virtues": ["Innovation +30"], "risks": ["Complexity -10"]},
15
  }
16
 
17
  def fetch_live_brainstorm(proposal_id, token=""):
18
  if not proposal_id:
19
  return "*The forge rejects the void—name thy proposal.*"
20
 
21
+ # Live Rite: Pi API for Brainstorm (App as Proposal)
22
  if token:
23
  headers = {"Authorization": f"Bearer {token}"}
24
  try:
 
25
  url = f"https://api.minepi.com/v2/apps/{proposal_id.upper()}"
26
  r = requests.get(url, headers=headers, timeout=10)
27
  if r.status_code == 200:
28
  data = r.json()
29
+ title = data.get('name', 'Live Proposal')
30
+ desc = data.get('description', 'From Pi Chain.')
31
  votes = data.get('votes', 0)
32
+ donations = data.get('donations', 0.0)
33
+ virtues = data.get('virtues', ["Live +10"])
34
+ risks = data.get('risks', ["No shadows"])
35
  return f"**{title}** (Votes: {votes} | Donations: {donations} Pi)\n{desc}\n\n**Virtues:** {'; '.join(virtues)}\n**Shadows:** {'; '.join(risks)}"
36
  except Exception as e:
37
+ return f"*Chain shadowed: {str(e)}. Echoing Brainstorm.*"
38
 
39
+ # Fallback: Hackathon Echo
40
  d = MOCK_BRAIN_STORM.get(proposal_id.upper(),
41
+ {"title": "Echo Proposal", "desc": "From Pi 2025 archives.", "votes": random.randint(100, 2000), "donations": random.uniform(50, 300), "virtues": ["Community +15"], "risks": ["Unverified -10"]})
42
+ 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'])}"
43
 
44
  def canticle_audit(proposal_id, token):
45
  if not proposal_id:
46
+ return "*Invoke to awaken.*", 0, "Awaiting", "0.0x"
47
 
48
+ echo = fetch_live_brainstorm(proposal_id, token)
49
+ virtues = echo.count("+")
50
+ risks = echo.count("-")
51
+ votes_bonus = int(''.join(filter(str.isdigit, echo.split("Votes:")[-1].split()[0]))) / 100 if "Votes:" in echo else 0
52
+ donations_bonus = float(''.join(filter(str.isdigit, str(echo.split("Donations:")[-1].split()[0].replace('.', ''))))) / 100 if "Donations:" in echo else 0
53
+ base = random.randint(60, 95)
54
+ score = max(0, min(100, base + virtues * 8 - risks * 12 + votes_bonus * 3 + donations_bonus * 5))
 
55
 
56
  resonance_map = {0: "Low", 40: "Medium", 70: "High", 90: "Transcendent"}
57
+ resonance = next((level for thresh, level in sorted(resonance_map.items(), reverse=True) if score >= thresh), "Low")
58
 
59
+ boost = max(0.1, min(3.0, score / 40 + votes_bonus / 2 + donations_bonus))
60
 
61
+ scroll = f"""
62
+ ## Canticle Audit: {proposal_id}
63
 
64
+ **Echo:** {echo}
65
 
66
+ **Verdict:**
67
+ - Scan: {virtues} virtues, {risks} shadows.
68
+ - Resonance: {resonance} (Score: {score} | Votes +{votes_bonus:.1f} | Donations +{donations_bonus:.1f} Pi).
69
 
70
+ **Boost:** {boost:.2f}x
71
 
72
+ *Brainstorm communes. Reforge.*
73
  """
74
 
75
+ return scroll, score, resonance, f"{boost:.2f}x"
76
 
77
+ # Interface: Veil in Blocks
78
+ with gr.Blocks(
79
+ title="LimitlessForge V1.4.1",
80
+ css_paths=["style.css"] # ← FIXED: Paths in Blocks
81
+ ) as demo:
82
  if CREST.exists():
83
  gr.HTML(f"<div class='banner'><img src='{CREST}' class='crest'/></div>")
84
 
85
+ gr.Markdown("# 🔨 LimitlessForge V1.4.1\n## Live Pi Brainstorm Auditor")
86
 
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
+ proposal_id = gr.Textbox(label="Proposal ID", placeholder="e.g., P-001", interactive=True)
90
+ pi_token = gr.Textbox(label="Pi Token (Optional)", type="password")
91
+ audit_btn = gr.Button("🔥 Strike Canticle", variant="primary")
92
 
93
  with gr.Column(scale=2):
94
+ project_echo = gr.Markdown("*Invoke a proposal...*")
95
 
96
  with gr.Row():
97
  ethical_score = gr.Number(label="Ethical Score", interactive=False)
98
  resonance = gr.Textbox(label="Resonance", interactive=False)
99
  mining_boost = gr.Textbox(label="Mining Boost", interactive=False)
100
 
101
+ audit_scroll = gr.Markdown("*The ledger awaits.*")
102
 
 
103
  audit_btn.click(
104
  fn=canticle_audit,
105
  inputs=[proposal_id, pi_token],
 
116
  outputs=project_echo
117
  )
118
 
119
+ gr.HTML("<div class='footer'><p class='footer-text'>Forged with Pi's Brainstorm. Eternal.</p></div>")
120
 
121
  if __name__ == "__main__":
122
+ demo.launch( # ← FIXED: Clean launch, no css_paths here
 
123
  server_name="0.0.0.0",
124
  server_port=7860,
125
  debug=True