Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
description = "This app predicts breast cancer based on digitized images of a fine needle aspirate (FNA) of a breast mass."
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = "Depression Prediction"
|
| 10 |
+
description = "This model predicts depression risk. Drag and drop any slice from dataset or edit values as you wish in below dataframe component."
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
with open("./config.json") as f:
|
| 14 |
+
config_dict = eval(f.read())
|
| 15 |
+
headers = config_dict["sklearn"]["columns"]
|
| 16 |
+
|
| 17 |
+
df = datasets.load_dataset("silvaKenpachi/mental_health")
|
| 18 |
+
df = df["train"].to_pandas()
|
| 19 |
+
df.dropna(axis=0, inplace=True)
|
| 20 |
+
|
| 21 |
+
feature_columns = [col for col in df.columns if col != 'Premium Amount']
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
inputs = [gr.Dataframe(headers = headers, row_count = (2, "dynamic"), col_count=(len(headers), "dynamic"), label="Input Data", interactive=1)]
|
| 26 |
+
outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Premium Amount"])]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def infer(inputs):
|
| 30 |
+
data = pd.DataFrame(inputs, columns=headers)
|
| 31 |
+
predictions = pipe.predict(inputs)
|
| 32 |
+
return pd.DataFrame(predictions, columns=["results"])
|
| 33 |
+
|
| 34 |
+
gr.Interface(infer, inputs = inputs, outputs = outputs, title = title,
|
| 35 |
+
description = description, examples=[df.head(3)], cache_examples=False).launch(debug=True)
|