import sklearn import gradio as gr import joblib import pandas as pd import datasets 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"] df = datasets.load_dataset("merve/supersoaker-failures") df = df["train"].to_pandas() df.dropna(axis=0, inplace=True) inputs = [gr.Dataframe(headers = headers, 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=headers) predictions = pipe.predict(inputs) return pd.DataFrame(predictions, columns=["results"]) gr.Interface(infer, inputs = inputs, outputs = outputs, title = title, description = description, examples=[df.head(3)], cache_examples=False).launch(debug=True)