| import sklearn | |
| import gradio as gr | |
| import joblib | |
| import pandas as pd | |
| pipe = joblib.load("./model.pkl") | |
| title = "Supersoaker Defective Product Prediction" | |
| description = "This model predicts Supersoaker production line failures. Drag and drop any slice from dataset or edit values as you wish in below dataframe component." | |
| with open("./config.json") as f: | |
| config_dict = eval(f.read()) | |
| headers = config_dict["sklearn"]["columns"] | |
| example_dict = config_dict["sklearn"]["example_input"] | |
| df = pd.DataFrame.from_dict(example_dict,orient='index').transpose() | |
| inputs = [gr.Dataframe(headers = [item for item in example_dict], row_count = (2, "dynamic"), col_count=(24,"dynamic"), label="Input Data", interactive=1)] | |
| outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Failures"])] | |
| def infer(inputs): | |
| data = pd.DataFrame(inputs, columns=[item for item in example_dict]) | |
| predictions = pipe.predict(inputs) | |
| return pd.DataFrame(predictions, columns=["results"]) | |
| gr.Interface(infer, inputs = inputs, outputs = outputs, title = title, | |
| description = description, examples=df.tail(3), cache_examples=False).launch(debug=True) | |