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

Create tab4_intrusion_detection.py

Browse files
Files changed (1) hide show
  1. tab/tab4_intrusion_detection.py +29 -0
tab/tab4_intrusion_detection.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():
22
+ with gr.Tab("4️⃣ Quantum Intrusion Detection"):
23
+ data_input = gr.Textbox(label="Data Stream (e.g. 0.3,0.7)")
24
+ detect_btn = gr.Button("Analyze")
25
+ detection_output = gr.Textbox(label="Detection Result")
26
+
27
+ detect_btn.click(quantum_intrusion_detection,
28
+ inputs=[data_input],
29
+ outputs=[detection_output])