kalpesh77 commited on
Commit
614bfca
ยท
verified ยท
1 Parent(s): 9846e6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -65
app.py CHANGED
@@ -1,99 +1,123 @@
1
  """
2
- app.py โ€” Simple Test Version
3
- Sri Yantra basic render โ€” no quantum interference
4
- Use this to diagnose HuggingFace rendering issues
5
  """
6
 
7
  import matplotlib
8
  matplotlib.use('Agg')
9
 
10
- import numpy as np
11
- import matplotlib.pyplot as plt
12
  import gradio as gr
 
13
  import io
14
  from PIL import Image
15
 
16
-
17
- def equilateral_triangle(cx, cy, r, pointing='up'):
18
- offset = np.pi if pointing == 'down' else 0
19
- angles = [np.pi/2 + offset + i * 2*np.pi/3 for i in range(3)]
20
- return np.array([(cx + r*np.cos(a), cy + r*np.sin(a)) for a in angles])
21
-
22
-
23
- def draw_simple_yantra(phase_shift=0.0):
24
- """Simple Sri Yantra โ€” no quantum overlay, basic triangles only."""
25
- fig, ax = plt.subplots(figsize=(6, 6), facecolor='#0d0010')
26
- ax.set_facecolor('#0d0010')
27
- ax.set_aspect('equal')
28
- ax.axis('off')
29
- ax.set_xlim(-1.5, 1.5)
30
- ax.set_ylim(-1.5, 1.5)
31
-
32
- # Outer circle
33
- t = np.linspace(0, 2*np.pi, 200)
34
- ax.plot(np.cos(t)*1.2, np.sin(t)*1.2, color='#DAA520', linewidth=1.0)
35
-
36
- # Shiva triangles (orange, pointing up)
37
- shiva = [(0.00,0.95),(0.10,0.60),(-0.05,0.38),(0.08,0.22)]
38
- for cy, r in shiva:
39
- v = equilateral_triangle(0, cy, r, 'up')
40
- poly = plt.Polygon(v, fill=True, facecolor='#FF6B35',
41
- alpha=0.25, edgecolor='#FF6B35', linewidth=1.5)
42
- ax.add_patch(poly)
43
-
44
- # Shakti triangles (pink, pointing down)
45
- shakti = [(-0.08,0.85),(0.00,0.65),(-0.10,0.48),(0.05,0.32),(-0.02,0.18)]
46
- for cy, r in shakti:
47
- v = equilateral_triangle(0, cy, r, 'down')
48
- poly = plt.Polygon(v, fill=True, facecolor='#C2185B',
49
- alpha=0.25, edgecolor='#C2185B', linewidth=1.5)
50
- ax.add_patch(poly)
51
-
52
- # Bindu
53
- ax.add_patch(plt.Circle((0, 0), 0.04, color='white', zorder=10))
54
- ax.add_patch(plt.Circle((0, 0), 0.10, color='#FFD700', alpha=0.3, zorder=9))
55
-
56
- # Title
57
- fig.text(0.5, 0.96, 'SRI YANTRA โ€” QUANTUM FIELD',
58
- ha='center', color='#FFD700', fontsize=11,
59
- fontweight='bold', fontfamily='monospace')
60
- fig.text(0.5, 0.02, f'Phase: {phase_shift:.2f} | vedic-logic.blogspot.com',
61
- ha='center', color='#888888', fontsize=7, fontfamily='monospace')
62
-
63
- plt.tight_layout(pad=0)
64
-
65
  buf = io.BytesIO()
66
- fig.savefig(buf, format='png', dpi=100,
67
- bbox_inches='tight', facecolor='#0d0010')
68
  buf.seek(0)
69
  plt.close(fig)
70
  return Image.open(buf)
71
 
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  with gr.Blocks(title="Vedic Simulation Visualizer") as demo:
74
 
75
  gr.Markdown("""
76
  # ๐Ÿ•‰ Sri Yantra โ€” Quantum Field Visualizer
77
  **vedic-logic.blogspot.com** | Branch 2: Simulation Theory
 
 
 
78
  """)
79
 
80
  with gr.Row():
81
  with gr.Column(scale=1):
82
- phase = gr.Slider(0, 6.28, value=0.0, step=0.1,
83
- label="Phase Shift")
84
- btn = gr.Button("๐Ÿ”ฎ Render Yantra", variant="primary")
 
 
 
 
 
 
85
  with gr.Column(scale=2):
86
- image_out = gr.Image(label="Sri Yantra", type="pil")
 
 
87
 
88
- btn.click(fn=draw_simple_yantra, inputs=[phase], outputs=image_out)
 
 
 
 
 
 
 
 
 
89
 
90
  gr.Markdown("""
91
  ---
92
- | Vedic | Quantum |
 
 
93
  |---|---|
94
- | Bindu | Wave function collapse |
95
- | 4 Shiva triangles | Qubit 0 basis |
96
- | 5 Shakti triangles | Qubit 1 basis |
 
 
 
 
 
 
 
97
  """)
98
 
 
99
  demo.launch()
 
 
1
  """
2
+ app.py โ€” HuggingFace Gradio Space
3
+ Vedic Simulation Visualizer: Sri Yantra โ†” Quantum Field
4
+ Gradio 6.0 compatible
5
  """
6
 
7
  import matplotlib
8
  matplotlib.use('Agg')
9
 
 
 
10
  import gradio as gr
11
+ import matplotlib.pyplot as plt
12
  import io
13
  from PIL import Image
14
 
15
+ from sri_yantra.visualizer import draw_sri_yantra
16
+ from sri_yantra.quantum_mapping import (
17
+ all_qubit_states, bindu_ground_state
18
+ )
19
+
20
+
21
+ def generate_sri_yantra(phase_shift, show_quantum, show_entanglement, show_labels):
22
+ """Gradio handler: render Sri Yantra and return as PIL image."""
23
+ fig = draw_sri_yantra(
24
+ phase_shift=phase_shift,
25
+ show_quantum=show_quantum,
26
+ show_entanglement=show_entanglement,
27
+ show_labels=show_labels,
28
+ figsize=(8, 8)
29
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  buf = io.BytesIO()
31
+ fig.savefig(buf, format='png', dpi=120, bbox_inches='tight', facecolor='#0d0010')
 
32
  buf.seek(0)
33
  plt.close(fig)
34
  return Image.open(buf)
35
 
36
 
37
+ def qubit_table(phase_shift):
38
+ """Return markdown table of all 9 qubit states."""
39
+ states = all_qubit_states(phase_shift)
40
+ rows = [
41
+ "| Layer | Type | P(0) Shiva | P(1) Shakti | Vedic Name |",
42
+ "|-------|------|-----------|------------|------------|"
43
+ ]
44
+ vedic_names = [
45
+ "Sarva Siddhi Prada", "Sarva Shakti Mayi", "Sarva Raksha Kara",
46
+ "Sarva Rogahara", "Sarva Siddhimaya", "Sarva Anandamaya",
47
+ "Sarva Raksha Kara II", "Sarva Siddhiprada", "Bindu Mandala"
48
+ ]
49
+ for i, s in enumerate(states):
50
+ name = vedic_names[i] if i < len(vedic_names) else "-"
51
+ tri_type = "Shiva" if s['type'] == 'shiva' else "Shakti"
52
+ rows.append(
53
+ f"| {s['layer']} | {tri_type} "
54
+ f"| {s['prob_0']:.3f} | {s['prob_1']:.3f} | {name} |"
55
+ )
56
+ alpha, beta = bindu_ground_state(phase_shift)
57
+ rows.append(
58
+ f"\n**Bindu Ground State:** P(0) = {abs(alpha)**2:.3f}, "
59
+ f"P(1) = {abs(beta)**2:.3f}"
60
+ )
61
+ return "\n".join(rows)
62
+
63
+
64
+ # โ”€โ”€ Gradio UI โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
65
+
66
  with gr.Blocks(title="Vedic Simulation Visualizer") as demo:
67
 
68
  gr.Markdown("""
69
  # ๐Ÿ•‰ Sri Yantra โ€” Quantum Field Visualizer
70
  **vedic-logic.blogspot.com** | Branch 2: Simulation Theory
71
+
72
+ The Sri Yantra encodes a **9-qubit quantum register** in sacred geometry.
73
+ Adjust the quantum phase shift to animate interference patterns.
74
  """)
75
 
76
  with gr.Row():
77
  with gr.Column(scale=1):
78
+ phase = gr.Slider(
79
+ 0, 6.28, value=0.0, step=0.05,
80
+ label="Quantum Phase Shift (0 to 2pi radians)"
81
+ )
82
+ show_q = gr.Checkbox(value=True, label="Show Interference Field")
83
+ show_e = gr.Checkbox(value=True, label="Show Entanglement Nodes")
84
+ show_l = gr.Checkbox(value=True, label="Show Labels")
85
+ btn = gr.Button("๐Ÿ”ฎ Render Yantra", variant="primary")
86
+
87
  with gr.Column(scale=2):
88
+ image_out = gr.Image(label="Sri Yantra Visualization", type="pil")
89
+
90
+ qubit_md = gr.Markdown()
91
 
92
+ btn.click(
93
+ fn=generate_sri_yantra,
94
+ inputs=[phase, show_q, show_e, show_l],
95
+ outputs=image_out
96
+ )
97
+ btn.click(
98
+ fn=qubit_table,
99
+ inputs=[phase],
100
+ outputs=qubit_md
101
+ )
102
 
103
  gr.Markdown("""
104
  ---
105
+ ### Vedic to Quantum Mapping
106
+
107
+ | Vedic Concept | Quantum Equivalent |
108
  |---|---|
109
+ | Bindu (central point) | Ground state โ€” wave function collapse |
110
+ | 4 Shiva triangles (up) | Qubit in 0 basis |
111
+ | 5 Shakti triangles (down) | Qubit in 1 basis |
112
+ | Intersection points | Entanglement nodes |
113
+ | Phase shift slider | Time evolution unitary operator |
114
+ | Sri Yantra whole | Hilbert space manifold |
115
+
116
+ ---
117
+ Blog: vedic-logic.blogspot.com |
118
+ GitHub: github.com/kalpeshnitore/vedic-simulation
119
  """)
120
 
121
+
122
  demo.launch()
123
+