File size: 3,232 Bytes
7578b4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""app.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1PufyNXKkKJpa1fHdbC5xMAHNAkAcB3UC
"""
import os
import uuid
import joblib
import json

import gradio as gr
import pandas as pd

from huggingface_hub import CommitScheduler
from pathlib import Path

log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
log_folder = log_file.parent

scheduler = CommitScheduler(
    repo_id="dsla_predictor",
    repo_type="dataset",
    folder_path=log_folder,
    path_in_repo="data",
    every=2
)

dsla_predictor = joblib.load('model.joblib')

snow_input = gr.Number(label='SNOW Instance')
priority_input = gr.Number(label='Priority 1-5')
sla_breached_input = gr.Number(label='SLA Breached 1=Yes, 0=No')
ci_input = gr.Dropdown(
    ['App1','App10','App11','App12','App13','App14','App15','App16','App17','App18','App19','App2','App20','App21','App22','App3','App4','App5','App6','App7','App8','App9','OTHER'],
    label='CI'
)

error_input = gr.Dropdown(
    'Access','Availability','Connectivity','Data','Error','Failure','File Transfer','Functionality','Info Security','Latency','Performance','Question','Request','Test',
    label='Error'
)

error_symptom_input = gr.Dropdown(
    ['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'],
    label='Error Symptom'
)

networkdays_input = gr.Number(label='Net Work Days')

model_output = gr.Label(label="dSLA Prediction")

def predict_dsla(snow, priority,sla_breached,ci,error,error_symptom,networkdays):
    sample = {
        'SNOW': snow,
        'Priority': priority,
        'SLA Breached': sla_breached,
        'CI': ci,
        'Error': error,
        'Error Symptom': error_symptom,
        'Network Days': networkdays
    }
    data_point = pd.DataFrame([sample])
    prediction = dsla_predictor.predict(data_point).tolist()

    with scheduler.lock:
        with log_file.open("a") as f:
            f.write(json.dumps(
                {
                    'SNOW': snow,
                    'Priority': priority,
                    'SLA Breached': sla_breached,
                    'CI': ci,
                    'Error': error,
                    'Error Symptom': error_symptom,
                    'Network Days': networkdays,
                    'prediction': prediction[0]
                }
            ))
            f.write("\n")

    return prediction[0]

demo = gr.Interface(
    fn=predict_dsla,
    inputs=[snow_input, priority_input, sla_breached_input, ci_input, error_input, error_symptom_input, networkdays_input],
    outputs=model_output,
    title="Dynamic SLA Predictor",
    description="This API allows you to predict the Dynamic SLA for an incident",
    allow_flagging="auto",
    concurrency_limit=8
)

demo.queue()
demo.launch(share=False)