Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sklearn
|
2 |
+
import gradio as gr
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
pipe = joblib.load("./model.pkl")
|
7 |
+
|
8 |
+
title = "Supersoaker Defective Product Prediction"
|
9 |
+
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."
|
10 |
+
|
11 |
+
|
12 |
+
with open("./config.json") as f:
|
13 |
+
config_dict = eval(f.read())
|
14 |
+
headers = config_dict["sklearn"]["columns"]
|
15 |
+
|
16 |
+
example_dict = config_dict["sklearn"]["example_input"]
|
17 |
+
df = pd.DataFrame.from_dict(example_dict,orient='index').transpose()
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
inputs = [gr.Dataframe(headers = [item for item in example_dict], row_count = (2, "dynamic"), col_count=(24,"dynamic"), label="Input Data", interactive=1)]
|
22 |
+
outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Failures"])]
|
23 |
+
|
24 |
+
|
25 |
+
def infer(inputs):
|
26 |
+
data = pd.DataFrame(inputs, columns=[item for item in example_dict])
|
27 |
+
predictions = pipe.predict(inputs)
|
28 |
+
return pd.DataFrame(predictions, columns=["results"])
|
29 |
+
|
30 |
+
gr.Interface(infer, inputs = inputs, outputs = outputs, title = title,
|
31 |
+
description = description, examples=df.tail(3), cache_examples=False).launch(debug=True)
|