Spaces:
Sleeping
Sleeping
File size: 10,525 Bytes
f5890d2 c7c644b f5890d2 bc8058c 9bfbb63 614bfca c7c644b 9bfbb63 f5890d2 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b 9bfbb63 c7c644b f5890d2 c7c644b f5890d2 c7c644b bc8058c f5890d2 a27a6f9 c7c644b f5890d2 c7c644b f5890d2 c7c644b f5890d2 c7c644b f5890d2 c7c644b f5890d2 9bfbb63 c7c644b f5890d2 | 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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | """
app.py โ HuggingFace Gradio Space
Sri Yantra โ Quantum Field Visualizer (Full Version)
vedic-logic.blogspot.com | Branch 2: Simulation Theory
"""
import matplotlib
matplotlib.use('Agg')
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import gradio as gr
import io
from PIL import Image
# โโโ Vedic color palette โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
VEDIC_CMAP = LinearSegmentedColormap.from_list('vedic', [
'#0a0010','#1a0030','#4b0082','#8b0000',
'#cc4400','#ff8c00','#ffd700','#ffffff'], N=256)
# โโโ Geometry โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def triangle_verts(cx, cy, r, pointing='up'):
offset = np.pi if pointing == 'down' else 0
angles = [np.pi/2 + offset + i*2*np.pi/3 for i in range(3)]
return np.array([(cx + r*np.cos(a), cy + r*np.sin(a)) for a in angles])
SHIVA_PARAMS = [(0.00,0.95,1),(0.10,0.60,3),(-0.05,0.38,5),(0.08,0.22,7)]
SHAKTI_PARAMS = [(-0.08,0.85,2),(0.00,0.65,4),(-0.10,0.48,6),(0.05,0.32,8),(-0.02,0.18,9)]
def get_triangles():
tris = []
for cy,r,layer in SHIVA_PARAMS:
tris.append({'v': triangle_verts(0,cy,r,'up'), 'type':'shiva', 'layer':layer})
for cy,r,layer in SHAKTI_PARAMS:
tris.append({'v': triangle_verts(0,cy,r,'down'), 'type':'shakti', 'layer':layer})
return sorted(tris, key=lambda t: t['layer'])
def lotus(n, r_in, r_out):
petals = []
for i in range(n):
a = 2*np.pi*i/n
t = np.linspace(0, 2*np.pi, 60)
px = 0.15*np.cos(t)
py = (r_out-r_in)/2*np.sin(t) + (r_in+r_out)/2
R = np.array([[np.cos(a),-np.sin(a)],[np.sin(a),np.cos(a)]])
c = R @ np.array([px, py])
petals.append((c[0], c[1]))
return petals
def outer_square(s=1.45, g=0.18):
lines = []
for si in [s, s-0.08]:
sq = np.array([[-si,-si],[si,-si],[si,si],[-si,si],[-si,-si]])
lines.append((sq[:,0], sq[:,1]))
for a in [0, np.pi/2, np.pi, 3*np.pi/2]:
R = np.array([[np.cos(a),-np.sin(a)],[np.sin(a),np.cos(a)]])
st = R @ np.array([[0,0],[s,s+g]]).T
cr = R @ np.array([[-g,g],[s+g,s+g]]).T
lines.append((st[0],st[1]))
lines.append((cr[0],cr[1]))
return lines
def seg_intersect(p1,p2,p3,p4):
d1,d2 = p2-p1, p4-p3
cross = d1[0]*d2[1]-d1[1]*d2[0]
if abs(cross)<1e-10: return None
t = ((p3[0]-p1[0])*d2[1]-(p3[1]-p1[1])*d2[0])/cross
u = ((p3[0]-p1[0])*d1[1]-(p3[1]-p1[1])*d1[0])/cross
if 0<=t<=1 and 0<=u<=1: return p1+t*d1
return None
def intersections(tris):
edges = []
for tri in tris:
v = tri['v']
for i in range(3): edges.append((v[i], v[(i+1)%3]))
pts = []
for i in range(len(edges)):
for j in range(i+1, len(edges)):
pt = seg_intersect(np.array(edges[i][0]),np.array(edges[i][1]),
np.array(edges[j][0]),np.array(edges[j][1]))
if pt is not None: pts.append(pt)
return np.array(pts) if pts else np.empty((0,2))
# โโโ Quantum โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def qubit(tri_type, layer, phase=0.0):
ln = layer/9.0
if tri_type == 'shiva':
a = np.cos(ln*np.pi/2)*np.exp(1j*phase)
b = np.sin(ln*np.pi/2)*np.exp(1j*(phase+np.pi/4))
else:
a = np.sin(ln*np.pi/2)*np.exp(1j*phase)
b = np.cos(ln*np.pi/2)*np.exp(1j*(phase+np.pi/4))
n = np.sqrt(abs(a)**2+abs(b)**2)
return a/n, b/n
def get_states(phase=0.0):
return [{'layer':t['layer'],'type':t['type'],
**dict(zip(['alpha','beta'], qubit(t['type'],t['layer'],phase))),
'prob_0':abs(qubit(t['type'],t['layer'],phase)[0])**2,
'prob_1':abs(qubit(t['type'],t['layer'],phase)[1])**2}
for t in get_triangles()]
def interference(res=120, phase=0.0):
x = np.linspace(-1.2,1.2,res)
y = np.linspace(-1.2,1.2,res)
X,Y = np.meshgrid(x,y)
Z = np.zeros_like(X, dtype=complex)
tris = get_triangles()
states = get_states(phase)
for tri,state in zip(tris,states):
cx,cy = tri['v'].mean(axis=0)
r = np.sqrt((X-cx)**2+(Y-cy)**2)+1e-6
amp = state['alpha']-state['beta']
k = 2*np.pi*(tri['layer']/3.0)
Z += amp*np.exp(1j*k*r)/r
return X,Y,np.abs(Z)**2
def bindu_state(phase=0.0):
states = get_states(phase)
ta = sum(s['alpha'] for s in states)
tb = sum(s['beta'] for s in states)
n = np.sqrt(abs(ta)**2+abs(tb)**2)
return ta/n, tb/n
# โโโ Renderer โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def render(phase_shift, show_quantum, show_entangle, show_labels):
fig, ax = plt.subplots(figsize=(8,8), facecolor='#0d0010')
ax.set_facecolor('#0d0010')
ax.set_aspect('equal')
ax.axis('off')
ax.set_xlim(-1.8,1.8)
ax.set_ylim(-1.8,1.8)
# Quantum heatmap
if show_quantum:
try:
X,Y,Z = interference(res=120, phase=phase_shift)
ax.contourf(X,Y,Z, levels=20, cmap=VEDIC_CMAP, alpha=0.5, zorder=1)
except Exception:
pass
# Bhupura
for lx,ly in outer_square():
ax.plot(lx,ly, color='#DAA520', linewidth=1.1, zorder=3)
# Circles
t = np.linspace(0,2*np.pi,200)
for r,a in [(1.18,0.9),(1.10,0.7),(1.02,0.5)]:
ax.plot(r*np.cos(t),r*np.sin(t), color='#DAA520', linewidth=0.8, alpha=a, zorder=3)
# Lotus
for xp,yp in lotus(16,0.92,1.08):
ax.fill(xp,yp, color='#cc4400', alpha=0.12, zorder=2)
ax.plot(xp,yp, color='#ff6a00', linewidth=0.5, alpha=0.5, zorder=3)
for xp,yp in lotus(8,0.75,0.92):
ax.fill(xp,yp, color='#8b0000', alpha=0.15, zorder=2)
ax.plot(xp,yp, color='#cc2200', linewidth=0.6, alpha=0.6, zorder=3)
# Triangles
tris = get_triangles()
states = get_states(phase_shift)
for tri,state in zip(tris,states):
color = '#FF6B35' if tri['type']=='shiva' else '#C2185B'
ax.add_patch(plt.Polygon(tri['v'], closed=True, fill=True,
facecolor=color, alpha=0.20+0.07*state['prob_0'],
edgecolor=color, linewidth=1.4, zorder=4))
# Entanglement nodes
if show_entangle:
pts = intersections(tris)
if len(pts)>0:
ax.scatter(pts[:,0],pts[:,1], s=6, c='#FFD700', alpha=0.7, zorder=6, linewidths=0)
# Bindu
ax.add_patch(plt.Circle((0,0),0.10, color='#FFD700', alpha=0.3, zorder=7))
ax.add_patch(plt.Circle((0,0),0.04, color='#FFFFFF', zorder=8))
# Labels
if show_labels:
ls = dict(color='#FFD700', fontsize=7, ha='center', va='center',
fontfamily='monospace', zorder=10,
bbox=dict(boxstyle='round,pad=0.2', fc='#0d0010', ec='#FFD700', alpha=0.7, lw=0.6))
ax.text(0,0.06,'BINDU', fontsize=6, color='white', ha='center', va='center', zorder=11)
ax.text(0,-1.55,'BHUPURA <-> Boundary Conditions', **ls)
ax.text(-1.6,0,'SHIVA\n|0>', **ls)
ax.text( 1.6,0,'SHAKTI\n|1>', **ls)
fig.text(0.5,0.97,'SRI YANTRA <-> QUANTUM FIELD',
ha='center', color='#FFD700', fontsize=12, fontweight='bold', fontfamily='monospace')
fig.text(0.5,0.02,f'Phase: {phase_shift:.2f} rad | vedic-logic.blogspot.com',
ha='center', color='#888888', fontsize=8, fontfamily='monospace')
plt.tight_layout(pad=0)
buf = io.BytesIO()
fig.savefig(buf, format='png', dpi=120, bbox_inches='tight', facecolor='#0d0010')
buf.seek(0)
plt.close(fig)
return Image.open(buf)
def make_table(phase_shift):
states = get_states(phase_shift)
names = ["Sarva Siddhi Prada","Sarva Shakti Mayi","Sarva Raksha Kara",
"Sarva Rogahara","Sarva Siddhimaya","Sarva Anandamaya",
"Sarva Raksha Kara II","Sarva Siddhiprada","Bindu Mandala"]
rows = ["| Layer | Type | P(0) | P(1) | Vedic Name |",
"|-------|------|------|------|------------|"]
for i,s in enumerate(states):
t = "Shiva" if s['type']=='shiva' else "Shakti"
rows.append(f"| {s['layer']} | {t} | {s['prob_0']:.3f} | {s['prob_1']:.3f} | {names[i]} |")
a,b = bindu_state(phase_shift)
rows.append(f"\n**Bindu:** P(0)={abs(a)**2:.3f} P(1)={abs(b)**2:.3f}")
return "\n".join(rows)
# โโโ Gradio UI โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Blocks(title="Vedic Simulation Visualizer") as demo:
gr.Markdown("""
# ๐ Sri Yantra โ Quantum Field Visualizer
**vedic-logic.blogspot.com** | Branch 2: Simulation Theory
Sri Yantra encodes a **9-qubit quantum register** in sacred geometry.
Adjust phase shift to animate quantum interference patterns.
""")
with gr.Row():
with gr.Column(scale=1):
phase = gr.Slider(0, 6.28, value=0.0, step=0.1,
label="Quantum Phase Shift (0 to 2pi)")
show_q = gr.Checkbox(value=True, label="Show Interference Field")
show_e = gr.Checkbox(value=True, label="Show Entanglement Nodes")
show_l = gr.Checkbox(value=True, label="Show Labels")
btn = gr.Button("๐ฎ Render Yantra", variant="primary")
with gr.Column(scale=2):
img_out = gr.Image(label="Sri Yantra", type="pil")
tbl_out = gr.Markdown()
btn.click(fn=render, inputs=[phase,show_q,show_e,show_l], outputs=img_out)
btn.click(fn=make_table, inputs=[phase], outputs=tbl_out)
gr.Markdown("""
---
### Vedic to Quantum Mapping
| Vedic Concept | Quantum Equivalent |
|---|---|
| Bindu | Wave function collapse |
| 4 Shiva triangles | Qubit 0 basis |
| 5 Shakti triangles | Qubit 1 basis |
| Intersection points | Entanglement nodes |
| Phase shift | Time evolution |
| Sri Yantra whole | Hilbert space manifold |
vedic-logic.blogspot.com | github.com/kalpeshnitore/vedic-simulation
""")
demo.launch()
|