Spaces:
Sleeping
Sleeping
Update tab/tab5_randomness_visualizer.py
Browse files
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("
|
| 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("
|
| 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("
|
| 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 |
-
|
|
|
|
|
|
|
| 101 |
randomness_text = gr.Textbox(label="Randomness Insight", lines=2)
|
| 102 |
|
| 103 |
-
|
|
|
|
| 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 |
+
])
|