raviix46 commited on
Commit
dc1f241
·
verified ·
1 Parent(s): fd3183f

Create tab5_randomness_visualizer.py

Browse files
Files changed (1) hide show
  1. tab/tab5_randomness_visualizer.py +28 -0
tab/tab5_randomness_visualizer.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ from io import BytesIO
4
+ from PIL import Image
5
+
6
+ def plot_key_bits(key_str):
7
+ bits = [int(b) for b in key_str.strip() if b in '01']
8
+ fig, ax = plt.subplots(figsize=(10, 2))
9
+ ax.bar(range(len(bits)), bits, color='skyblue')
10
+ ax.set_title("Bit Distribution of QKD Key")
11
+ ax.set_xlabel("Bit Index")
12
+ ax.set_ylabel("Bit Value")
13
+ plt.tight_layout()
14
+ buf = BytesIO()
15
+ plt.savefig(buf, format='png')
16
+ plt.close()
17
+ buf.seek(0)
18
+ return Image.open(buf)
19
+
20
+ def get_tab5_randomness():
21
+ with gr.Tab("📊 QKD Key Randomness Visualizer"):
22
+ binary_input = gr.Textbox(label="Enter QKD Key (binary)", lines=3)
23
+ visualize_btn = gr.Button("Plot Bit Distribution")
24
+ graph_output = gr.Image(label="Randomness Graph")
25
+
26
+ visualize_btn.click(plot_key_bits,
27
+ inputs=[binary_input],
28
+ outputs=[graph_output])