raviix46 commited on
Commit
eb43a65
Β·
verified Β·
1 Parent(s): cedc3b8

Delete tab/tab4_intrusion_detection.py

Browse files
Files changed (1) hide show
  1. tab/tab4_intrusion_detection.py +0 -64
tab/tab4_intrusion_detection.py DELETED
@@ -1,64 +0,0 @@
1
- import gradio as gr
2
- import pennylane as qml
3
-
4
- def quantum_intrusion_detection(data_stream):
5
- dev = qml.device("default.qubit", wires=2)
6
-
7
- @qml.qnode(dev)
8
- def classifier(x):
9
- qml.RY(x[0], wires=0)
10
- qml.RY(x[1], wires=1)
11
- qml.CNOT(wires=[0, 1])
12
- return qml.expval(qml.PauliZ(0))
13
-
14
- try:
15
- x = [float(i) for i in data_stream.split(',')]
16
- score = abs(classifier(x))
17
- return "🚨 Intrusion Detected" if score > 0.7 else "βœ… Normal Activity"
18
- except:
19
- return "❌ Invalid input. Format: 0.3,0.7"
20
-
21
- def get_tab4_intrusion_detection():
22
- with gr.Tab('πŸ§ͺ Bonus: Quantum Threat Monitor'):
23
- gr.Markdown("""
24
- ## 🧠 Experimental: Quantum Threat Monitor
25
-
26
- > This is a **bonus demonstration tab** showing how quantum circuits can help with **threat detection** in communication systems.
27
-
28
- It uses a **2-qubit quantum circuit** to classify simple data streams as:
29
- - βœ… Normal Activity
30
- - 🚨 Intrusion Detected
31
-
32
- While not part of the core QKD pipeline, it showcases how **quantum machine learning** may play a role in **post-quantum security monitoring**.
33
-
34
- ### πŸ’‘ How to Use:
35
- - Choose a **sample data stream** or enter your own (e.g., `0.3,0.7`)
36
- - Click **Analyze** to detect potential threats.
37
- """)
38
-
39
- example_inputs = {
40
- "🟒 Normal Activity (e.g. idle)": "0.1,0.2",
41
- "🟑 Slightly Suspicious": "0.4,0.6",
42
- "πŸ”΄ Potential Intrusion": "0.8,0.9"
43
- }
44
-
45
- dropdown = gr.Dropdown(
46
- label="πŸ”½ Select Sample Data Stream",
47
- choices=list(example_inputs.keys()),
48
- value="🟒 Normal Activity (e.g. idle)"
49
- )
50
-
51
- data_input = gr.Textbox(label="Or Enter Custom Data Stream (e.g. 0.3,0.7)", lines=1)
52
- detect_btn = gr.Button("πŸ” Analyze")
53
- detection_output = gr.Textbox(label="Detection Result")
54
-
55
- def fill_example(choice):
56
- return example_inputs[choice]
57
-
58
- dropdown.change(fn=fill_example, inputs=[dropdown], outputs=[data_input])
59
-
60
- detect_btn.click(
61
- quantum_intrusion_detection,
62
- inputs=[data_input],
63
- outputs=[detection_output]
64
- )