Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| from joblib import dump, load | |
| from sklearn.model_selection import train_test_split | |
| from catboost import CatBoostClassifier, Pool | |
| #, MetricVisualizer | |
| from sklearn.model_selection import GridSearchCV | |
| from sklearn.neighbors import KernelDensity | |
| import matplotlib.pyplot as plt | |
| import matplotlib | |
| #Model Loading | |
| model = load("modelUser_Behavior.pkl") | |
| def predict_behavior_type(evaluation): | |
| prediction = model.predict(evaluation) | |
| return prediction | |
| def analyze_data(inter_api_access_duration, api_access_uniqueness, sequence_length, vsession_duration, ip_type, num_sessions, num_users, num_unique_apis): | |
| # Combine the input parameters into a single evaluation object or use them individually as needed | |
| evaluation = [inter_api_access_duration, api_access_uniqueness, sequence_length, vsession_duration, ip_type, num_sessions, num_users, num_unique_apis] | |
| # Call the model's predict function with the evaluation object or individual parameters as needed | |
| prediction = predict_behavior_type(evaluation) | |
| # Return the prediction or any output you desire | |
| return prediction | |
| # Create a Gradio Dataframe input with three columns and two rows | |
| inter_api_access_duration_input = gr.inputs.Number(label="Inter API Access Duration (sec)") | |
| api_access_uniqueness_input = gr.inputs.Number(label="API Access Uniqueness") | |
| sequence_length_input = gr.inputs.Number(label="Sequence Length (count)") | |
| vsession_duration_input = gr.inputs.Number(label="VSession Duration (min)") | |
| ip_type_input = gr.inputs.Dropdown(choices=["default", "alternative","datacenter"], label="IP Type") | |
| num_sessions_input = gr.inputs.Number(label="Number of Sessions") | |
| num_users_input = gr.inputs.Number(label="Number of Users") | |
| num_unique_apis_input = gr.inputs.Number(label="Number of Unique APIs") | |
| Inputs = [inter_api_access_duration_input, api_access_uniqueness_input, sequence_length_input, | |
| vsession_duration_input, ip_type_input, num_sessions_input, num_users_input, num_unique_apis_input] | |
| # Define your output | |
| output = gr.outputs.Textbox(label="Analysis Result") | |
| examples = [ | |
| [0.000721, 0.019527, 12.960905, 273, "default", 708.0, 486.0, 123.0], | |
| [0.000112, 0.002958, 20.859897, 109, "default", 1152.0, 778.0, 48.0], | |
| [0.003907, 0.005867, 20.262226, 5635, "alternative", 1288.0, 1186.0, 141.0], | |
| [0.120327, 0.5, 26, 188, "default", 8.0, 1.0, 13.0], | |
| [0.000544, 0.128842, 8.294118, 28, "alternative", 134.0, 102.0, 109.0], | |
| [852.92925, 0.5, 2.0, 102352, "datacenter", 2.0, 1.0, 1.0], | |
| [59.243, 0.8, 5.0, 17773, "datacenter", 3.0, 1.0, 4.0], | |
| [0.754, 0.6666666666666666, 3.0, 136, "datacenter", 2.0, 1.0, 2.0], | |
| [66.93485714285714, 0.4285714285714285, 7.0, 28113, "datacenter", 3.0, 1.0, 3.0] | |
| ] | |
| # Define your Gradio interface | |
| interface = gr.Interface(fn=analyze_data, inputs=Inputs,examples=examples, outputs=output, title="API Data Analysis~ Group No. 12", | |
| description=''' | |
| Analyze API data using the specified inputs. | |
| 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. | |
| api_access_uniqueness_input: It is a numerical input represented by a number field. Users can enter the level of uniqueness in API access. | |
| sequence_length_input: It is a numerical input represented by a number field. Users can enter the length of the sequence in counts. | |
| vsession_duration_input: It is a numerical input represented by a number field. Users can enter the duration of virtual sessions in minutes. | |
| ip_type_input: It is a dropdown input with two choices ("default" and "alternative"). Users can select the type of IP address. | |
| num_sessions_input: It is a numerical input represented by a number field. Users can enter the number of sessions. | |
| num_users_input: It is a numerical input represented by a number field. Users can enter the number of users. | |
| num_unique_apis_input: It is a numerical input represented by a number field. Users can enter the number of unique APIs. | |
| ''', | |
| layout="horizontal", | |
| verbose=True) | |
| # Launch the interface | |
| interface.launch() | |