Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
def make(Flow_Bytes_per_s,Fwd_Packets_Length_Total,Init_Fwd_Win_Bytes,Packet_Length_Variance,Packet_Length_Std,Down_Up_Ratio,Flow_IAT_Min,ACK_Flag_Count,Init_Bwd_Win_Bytes,Fwd_Seg_Size_Min,Bwd_Packet_Length_Min,Fwd_Packet_Length_Std,Fwd_IAT_Min,Fwd_Header_Length,URG_Flag_Count):
|
| 4 |
+
#def make(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o):
|
| 5 |
+
#l=[Flow Bytes/s,Fwd Packets Length Total,Init Fwd Win Bytes,Packet Length Variance,Packet Length Std,Down/Up Ratio,Flow IAT Min,ACK Flag Count,Init Bwd Win Bytes,Fwd Seg Size Min,Bwd Packet Length Min,Fwd Packet Length Std,Fwd IAT Min,Fwd Header Length,URG Flag Count]
|
| 6 |
+
# Input =Input.strip("'") # Remove leading and trailing double quotes
|
| 7 |
+
#l=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o]
|
| 8 |
+
l=[Flow_Bytes_per_s,Fwd_Packets_Length_Total,Init_Fwd_Win_Bytes,Packet_Length_Variance,Packet_Length_Std,Down_Up_Ratio,Flow_IAT_Min,ACK_Flag_Count,Init_Bwd_Win_Bytes,Fwd_Seg_Size_Min,Bwd_Packet_Length_Min,Fwd_Packet_Length_Std,Fwd_IAT_Min,Fwd_Header_Length,URG_Flag_Count]
|
| 9 |
+
reverse_encoding={
|
| 10 |
+
0:"Benign",
|
| 11 |
+
1:"DNS",
|
| 12 |
+
2:"LDAP",
|
| 13 |
+
3:'MSSQL',
|
| 14 |
+
4:"NTP",
|
| 15 |
+
5:"NetBIOS",
|
| 16 |
+
6:"Portmap",
|
| 17 |
+
7:"SNMP",
|
| 18 |
+
8:"Syn",
|
| 19 |
+
9:"TFTP",
|
| 20 |
+
10:"UDP",
|
| 21 |
+
11:"UDPLag",
|
| 22 |
+
12:"WebDDoS"}
|
| 23 |
+
s=[]
|
| 24 |
+
s.append(l)
|
| 25 |
+
loaded_model = joblib.load('your_model.pkl')
|
| 26 |
+
predictions=loaded_model.predict(s)
|
| 27 |
+
# for i in range(len(predictions)):
|
| 28 |
+
# print("Prediction",i+1,':',reverse_encoding[predictions[i]])
|
| 29 |
+
import csv
|
| 30 |
+
input_file = "predictions.csv"
|
| 31 |
+
new_row = l
|
| 32 |
+
new_row.append(reverse_encoding[predictions[0]])
|
| 33 |
+
with open(input_file, 'r', newline='') as infile:
|
| 34 |
+
reader = csv.reader(infile)
|
| 35 |
+
data = list(reader)
|
| 36 |
+
with open(input_file, 'a', newline='') as outfile:
|
| 37 |
+
writer = csv.writer(outfile)
|
| 38 |
+
writer.writerow(new_row)
|
| 39 |
+
return reverse_encoding[predictions[0]]
|
| 40 |
+
headline ="""
|
| 41 |
+
Department of Information Technology \n
|
| 42 |
+
National Institute of Technology Karnataka \n
|
| 43 |
+
Contributors: Mahit Nandan (211AI001), Ishan Godbole (211AI020) \n
|
| 44 |
+
Course Instructor: Dr. Jaidhar C.D.
|
| 45 |
+
DDoS Attack Classification
|
| 46 |
+
"""
|
| 47 |
+
iface=gr.Interface(fn=make,
|
| 48 |
+
inputs=[gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float),gr.Number(value=float)],
|
| 49 |
+
outputs="text",title=headline)
|
| 50 |
+
# iface.launch(share=True)
|
| 51 |
+
iface.launch(share=False,debug=False)
|