Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""app.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1PufyNXKkKJpa1fHdbC5xMAHNAkAcB3UC
|
8 |
+
"""
|
9 |
+
|
10 |
+
!pip install gradio
|
11 |
+
|
12 |
+
import os
|
13 |
+
import uuid
|
14 |
+
import joblib
|
15 |
+
import json
|
16 |
+
|
17 |
+
import gradio as gr
|
18 |
+
import pandas as pd
|
19 |
+
|
20 |
+
from huggingface_hub import CommitScheduler
|
21 |
+
from pathlib import Path
|
22 |
+
|
23 |
+
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
24 |
+
log_folder = log_file.parent
|
25 |
+
|
26 |
+
scheduler = CommitScheduler(
|
27 |
+
repo_id="dsla_predictor",
|
28 |
+
repo_type="dataset",
|
29 |
+
folder_path=log_folder,
|
30 |
+
path_in_repo="data",
|
31 |
+
every=2
|
32 |
+
)
|
33 |
+
|
34 |
+
dsla_predictor = joblib.load('model.joblib')
|
35 |
+
|
36 |
+
snow_input = gr.Number(label='SNOW Instance')
|
37 |
+
priority_input = gr.Number(label='Priority 1-5')
|
38 |
+
sla_breached_input = gr.Number(label='SLA Breached 1=Yes, 0=No')
|
39 |
+
ci_input = gr.Dropdown(
|
40 |
+
['App1','App10','App11','App12','App13','App14','App15','App16','App17','App18','App19','App2','App20','App21','App22','App3','App4','App5','App6','App7','App8','App9','OTHER'],
|
41 |
+
label='CI'
|
42 |
+
)
|
43 |
+
|
44 |
+
error_input = gr.Dropdown(
|
45 |
+
'Access','Availability','Connectivity','Data','Error','Failure','File Transfer','Functionality','Info Security','Latency','Performance','Question','Request','Test',
|
46 |
+
label='Error'
|
47 |
+
)
|
48 |
+
|
49 |
+
error_symptom_input = gr.Dropdown(
|
50 |
+
['Account Issue','Application Functionality','Authentication Service Issue','Batch Job','BC Testing','Business Process/Event','Business Process/Rule','Client Side Error','Data Fix','External Mailing','General','Hardware','How To','Human Error','Impacting Normal Operations','Inaccurate Data','Inaccurate Data - Back Office','Inaccurate Data - Client Facing','Inbound Feed Delay','Inbound Feed Failure','Intermittent','Intermittent (Client)','Intermittent (PRU)','Investigation'],
|
51 |
+
label='Error Symptom'
|
52 |
+
)
|
53 |
+
|
54 |
+
networkdays_input = gr.Number(label='Net Work Days')
|
55 |
+
|
56 |
+
model_output = gr.Label(label="dSLA Prediction")
|
57 |
+
|
58 |
+
def predict_dsla(snow, priority,sla_breached,ci,error,error_symptom,networkdays):
|
59 |
+
sample = {
|
60 |
+
'SNOW': snow,
|
61 |
+
'Priority': priority,
|
62 |
+
'SLA Breached': sla_breached,
|
63 |
+
'CI': ci,
|
64 |
+
'Error': error,
|
65 |
+
'Error Symptom': error_symptom,
|
66 |
+
'Network Days': networkdays
|
67 |
+
}
|
68 |
+
data_point = pd.DataFrame([sample])
|
69 |
+
prediction = dsla_predictor.predict(data_point).tolist()
|
70 |
+
|
71 |
+
with scheduler.lock:
|
72 |
+
with log_file.open("a") as f:
|
73 |
+
f.write(json.dumps(
|
74 |
+
{
|
75 |
+
'SNOW': snow,
|
76 |
+
'Priority': priority,
|
77 |
+
'SLA Breached': sla_breached,
|
78 |
+
'CI': ci,
|
79 |
+
'Error': error,
|
80 |
+
'Error Symptom': error_symptom,
|
81 |
+
'Network Days': networkdays,
|
82 |
+
'prediction': prediction[0]
|
83 |
+
}
|
84 |
+
))
|
85 |
+
f.write("\n")
|
86 |
+
|
87 |
+
return prediction[0]
|
88 |
+
|
89 |
+
demo = gr.Interface(
|
90 |
+
fn=predict_dsla,
|
91 |
+
inputs=[snow_input, priority_input, sla_breached_input, ci_input, error_input, error_symptom_input, networkdays_input],
|
92 |
+
outputs=model_output,
|
93 |
+
title="Dynamic SLA Predictor",
|
94 |
+
description="This API allows you to predict the Dynamic SLA for an incident",
|
95 |
+
allow_flagging="auto",
|
96 |
+
concurrency_limit=8
|
97 |
+
)
|
98 |
+
|
99 |
+
demo.queue()
|
100 |
+
demo.launch(share=False)
|