Pranjal-psytech commited on
Commit
3599d25
1 Parent(s): c4a182c

"Model~Load"

Browse files
Files changed (2) hide show
  1. app.py +86 -4
  2. modelUser_Behavior.pkl +3 -0
app.py CHANGED
@@ -1,7 +1,89 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from joblib import dump, load
5
+ from sklearn.model_selection import train_test_split
6
+ from catboost import CatBoostClassifier, MetricVisualizer, Pool
7
+ from sklearn.model_selection import GridSearchCV
8
+ from sklearn.neighbors import KernelDensity
9
+ import matplotlib.pyplot as plt
10
+ import matplotlib
11
 
12
+ #Model Loading
13
+ model = load('modelUser_Behavior.pkl')
14
+
15
+
16
+
17
+
18
+ def predict_behavior_type(evaluation):
19
+ prediction = model.predict(evaluation)
20
+ return prediction
21
+
22
+
23
+
24
+
25
+ def analyze_data(inter_api_access_duration, api_access_uniqueness, sequence_length, vsession_duration, ip_type, num_sessions, num_users, num_unique_apis):
26
+ # Combine the input parameters into a single evaluation object or use them individually as needed
27
+ evaluation = [inter_api_access_duration, api_access_uniqueness, sequence_length, vsession_duration, ip_type, num_sessions, num_users, num_unique_apis]
28
+
29
+ # Call the model's predict function with the evaluation object or individual parameters as needed
30
+ prediction = predict_behavior_type(evaluation)
31
+
32
+ # Return the prediction or any output you desire
33
+ return prediction
34
+
35
+
36
+ # Create a Gradio Dataframe input with three columns and two rows
37
+ inter_api_access_duration_input = gr.inputs.Number(label="Inter API Access Duration (sec)")
38
+ api_access_uniqueness_input = gr.inputs.Number(label="API Access Uniqueness")
39
+ sequence_length_input = gr.inputs.Number(label="Sequence Length (count)")
40
+ vsession_duration_input = gr.inputs.Number(label="VSession Duration (min)")
41
+ ip_type_input = gr.inputs.Dropdown(choices=["default", "alternative","datacenter"], label="IP Type")
42
+ num_sessions_input = gr.inputs.Number(label="Number of Sessions")
43
+ num_users_input = gr.inputs.Number(label="Number of Users")
44
+ num_unique_apis_input = gr.inputs.Number(label="Number of Unique APIs")
45
+
46
+ Inputs = [inter_api_access_duration_input, api_access_uniqueness_input, sequence_length_input,
47
+ vsession_duration_input, ip_type_input, num_sessions_input, num_users_input, num_unique_apis_input]
48
+ # Define your output
49
+ output = gr.outputs.Textbox(label="Analysis Result")
50
+
51
+ examples = [
52
+ [0.000721, 0.019527, 12.960905, 273, "default", 708.0, 486.0, 123.0],
53
+ [0.000112, 0.002958, 20.859897, 109, "default", 1152.0, 778.0, 48.0],
54
+ [0.003907, 0.005867, 20.262226, 5635, "alternative", 1288.0, 1186.0, 141.0],
55
+ [0.120327, 0.5, 26, 188, "default", 8.0, 1.0, 13.0],
56
+ [0.000544, 0.128842, 8.294118, 28, "alternative", 134.0, 102.0, 109.0],
57
+ [852.92925, 0.5, 2.0, 102352, "datacenter", 2.0, 1.0, 1.0],
58
+ [59.243, 0.8, 5.0, 17773, "datacenter", 3.0, 1.0, 4.0],
59
+ [0.754, 0.6666666666666666, 3.0, 136, "datacenter", 2.0, 1.0, 2.0],
60
+ [66.93485714285714, 0.4285714285714285, 7.0, 28113, "datacenter", 3.0, 1.0, 3.0]
61
+ ]
62
+
63
+
64
+ # Define your Gradio interface
65
+ interface = gr.Interface(fn=analyze_data, inputs=Inputs,examples=examples, outputs=output, title="API Data Analysis~ Group No. 12",
66
+ description='''
67
+ Analyze API data using the specified inputs.
68
+
69
+ inter_api_access_duration_input: It is a numerical input represented by a number field. Users can enter the duration of inter API access in seconds.
70
+
71
+ api_access_uniqueness_input: It is a numerical input represented by a number field. Users can enter the level of uniqueness in API access.
72
+
73
+ sequence_length_input: It is a numerical input represented by a number field. Users can enter the length of the sequence in counts.
74
+
75
+ vsession_duration_input: It is a numerical input represented by a number field. Users can enter the duration of virtual sessions in minutes.
76
+
77
+ ip_type_input: It is a dropdown input with two choices ("default" and "alternative"). Users can select the type of IP address.
78
+
79
+ num_sessions_input: It is a numerical input represented by a number field. Users can enter the number of sessions.
80
+
81
+ num_users_input: It is a numerical input represented by a number field. Users can enter the number of users.
82
+
83
+ num_unique_apis_input: It is a numerical input represented by a number field. Users can enter the number of unique APIs.
84
+ ''',
85
+ layout="horizontal",
86
+ verbose=True)
87
+ # Launch the interface
88
+ interface.launch()
89
 
 
 
modelUser_Behavior.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57fb9ada224c5d5cc28ae296d9e19cff5341a0b310dd2d010f9f163c80eb7262
3
+ size 64834