raviix46 commited on
Commit
30e51cd
Β·
verified Β·
1 Parent(s): 90f44f8

Update tab/tab5_randomness_visualizer.py

Browse files
Files changed (1) hide show
  1. tab/tab5_randomness_visualizer.py +21 -6
tab/tab5_randomness_visualizer.py CHANGED
@@ -20,7 +20,7 @@ def plot_key_randomness(key_str):
20
 
21
  fig, ax = plt.subplots(figsize=(12, 2.5))
22
  ax.bar(range(total_bits), heights, color=colors, edgecolor='black', linewidth=0.2)
23
- ax.set_title("πŸ” Bit Distribution: 0s (Blue) vs 1s (Orange)", fontsize=12)
24
  ax.set_xlabel("Bit Position")
25
  ax.set_yticks([])
26
 
@@ -68,13 +68,13 @@ def compare_original_vs_noisy(key_str):
68
  fig, axs = plt.subplots(2, 1, figsize=(12, 3.8), sharex=True)
69
 
70
  axs[0].bar(x, heights, color='green', edgecolor='black', linewidth=0.2)
71
- axs[0].set_title("🟒 Before Noise: Original QKD Key", fontsize=11)
72
  axs[0].set_yticks([])
73
  axs[0].set_ylabel("Bit")
74
 
75
  colors = ['red' if i in flipped_indices else 'green' for i in range(total_bits)]
76
  axs[1].bar(x, heights, color=colors, edgecolor='black', linewidth=0.2)
77
- axs[1].set_title("πŸ”΄ After Noise: Key with Eavesdropper Flips", fontsize=11)
78
  axs[1].set_xlabel("Bit Index")
79
  axs[1].set_yticks([])
80
  axs[1].set_ylabel("Bit")
@@ -97,10 +97,13 @@ def get_tab5_randomness():
97
 
98
  process_btn = gr.Button("Analyze Key")
99
 
100
- randomness_graph = gr.Image(label="πŸ§ͺ Bit Distribution Graph")
 
 
101
  randomness_text = gr.Textbox(label="Randomness Insight", lines=2)
102
 
103
- noise_graph = gr.Image(label="πŸ” Noise Simulation (Original vs Flipped Bits)")
 
104
  noise_summary = gr.Textbox(label="Noise Impact Summary", lines=2)
105
 
106
  def full_analysis(binary_key):
@@ -116,4 +119,16 @@ def get_tab5_randomness():
116
  randomness_graph, randomness_text,
117
  noise_graph, noise_summary
118
  ]
119
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  fig, ax = plt.subplots(figsize=(12, 2.5))
22
  ax.bar(range(total_bits), heights, color=colors, edgecolor='black', linewidth=0.2)
23
+ ax.set_title("Visual Analysis of Bit Distribution: 0s vs 1s", fontsize=13)
24
  ax.set_xlabel("Bit Position")
25
  ax.set_yticks([])
26
 
 
68
  fig, axs = plt.subplots(2, 1, figsize=(12, 3.8), sharex=True)
69
 
70
  axs[0].bar(x, heights, color='green', edgecolor='black', linewidth=0.2)
71
+ axs[0].set_title("Before Noise: Original QKD Key", fontsize=11)
72
  axs[0].set_yticks([])
73
  axs[0].set_ylabel("Bit")
74
 
75
  colors = ['red' if i in flipped_indices else 'green' for i in range(total_bits)]
76
  axs[1].bar(x, heights, color=colors, edgecolor='black', linewidth=0.2)
77
+ axs[1].set_title("After Noise: Key with Eavesdropper Flips", fontsize=11)
78
  axs[1].set_xlabel("Bit Index")
79
  axs[1].set_yticks([])
80
  axs[1].set_ylabel("Bit")
 
97
 
98
  process_btn = gr.Button("Analyze Key")
99
 
100
+ # Headings above graphs (as Markdown HTML boxes)
101
+ randomness_heading = gr.Markdown("### πŸ“ˆ Graph 1: Bit Randomness Distribution")
102
+ randomness_graph = gr.Image(label="πŸ§ͺ Distribution of 0s and 1s in your key")
103
  randomness_text = gr.Textbox(label="Randomness Insight", lines=2)
104
 
105
+ noise_heading = gr.Markdown("### 🧨 Graph 2: Noise Simulation – Flipped Bits due to Eavesdropping")
106
+ noise_graph = gr.Image(label="πŸ” Original vs Flipped Bits")
107
  noise_summary = gr.Textbox(label="Noise Impact Summary", lines=2)
108
 
109
  def full_analysis(binary_key):
 
119
  randomness_graph, randomness_text,
120
  noise_graph, noise_summary
121
  ]
122
+ )
123
+
124
+ # Layout all elements together
125
+ gr.Column([
126
+ input_key,
127
+ process_btn,
128
+ randomness_heading,
129
+ randomness_graph,
130
+ randomness_text,
131
+ noise_heading,
132
+ noise_graph,
133
+ noise_summary
134
+ ])