Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,39 @@
|
|
1 |
-
import sklearn
|
2 |
import gradio as gr
|
3 |
import joblib
|
4 |
import pandas as pd
|
5 |
import datasets
|
|
|
6 |
|
|
|
7 |
pipe = joblib.load("./model.pkl")
|
8 |
|
9 |
-
title = "
|
10 |
-
description = "This model predicts
|
11 |
-
|
12 |
|
|
|
13 |
with open("./config.json") as f:
|
14 |
-
config_dict =
|
15 |
headers = config_dict["sklearn"]["columns"]
|
16 |
|
17 |
-
|
18 |
-
df =
|
19 |
df.dropna(axis=0, inplace=True)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Depression"])]
|
25 |
-
|
26 |
|
27 |
def infer(inputs):
|
28 |
data = pd.DataFrame(inputs, columns=headers)
|
29 |
-
predictions = pipe.predict(
|
30 |
return pd.DataFrame(predictions, columns=["Depression"])
|
31 |
|
32 |
-
gr.Interface(
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import joblib
|
3 |
import pandas as pd
|
4 |
import datasets
|
5 |
+
import json
|
6 |
|
7 |
+
# Load the model
|
8 |
pipe = joblib.load("./model.pkl")
|
9 |
|
10 |
+
title = "Premium Amount Prediction"
|
11 |
+
description = "This model predicts the Premium Amount. Drag and drop any slice from the dataset or edit values as you wish in the dataframe component below."
|
|
|
12 |
|
13 |
+
# Load configuration
|
14 |
with open("./config.json") as f:
|
15 |
+
config_dict = json.load(f)
|
16 |
headers = config_dict["sklearn"]["columns"]
|
17 |
|
18 |
+
# Load and prepare dataset
|
19 |
+
df = datasets.load_dataset("silvaKenpachi/mental_health")["train"].to_pandas()
|
20 |
df.dropna(axis=0, inplace=True)
|
21 |
|
22 |
+
# Define input and output interfaces
|
23 |
+
inputs = [gr.Dataframe(headers=headers, row_count=(2, "dynamic"), col_count=(len(headers), "fixed"), label="Input Data", interactive=True)]
|
24 |
+
outputs = [gr.Dataframe(row_count=(2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Depression"])]
|
|
|
|
|
25 |
|
26 |
def infer(inputs):
|
27 |
data = pd.DataFrame(inputs, columns=headers)
|
28 |
+
predictions = pipe.predict(data)
|
29 |
return pd.DataFrame(predictions, columns=["Depression"])
|
30 |
|
31 |
+
gr.Interface(
|
32 |
+
fn=infer,
|
33 |
+
inputs=inputs,
|
34 |
+
outputs=outputs,
|
35 |
+
title=title,
|
36 |
+
description=description,
|
37 |
+
examples=[df[headers].head(3).values.tolist()],
|
38 |
+
cache_examples=False
|
39 |
+
).launch(debug=True)
|