silvaKenpachi commited on
Commit
12c727d
·
verified ·
1 Parent(s): d924060

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
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 = "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
-
22
-
23
- inputs = [gr.Dataframe(headers = headers, row_count = (2, "dynamic"), col_count=(len(headers), "dynamic"), label="Input Data", interactive=1)]
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(inputs)
30
  return pd.DataFrame(predictions, columns=["Depression"])
31
 
32
- gr.Interface(infer, inputs = inputs, outputs = outputs, title = title,
33
- description = description, examples=[df.head(3)], cache_examples=False).launch(debug=True)
 
 
 
 
 
 
 
 
 
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)