dsla_prototype / app.py
Lrosado's picture
Upload app.py
2075d99 verified
# -*- 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)