silvaKenpachi commited on
Commit
b0e84c2
·
verified ·
1 Parent(s): 22468ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -23,14 +23,27 @@ all_headers = config_dict["sklearn"]["columns"]
23
  headers = [col for col in all_headers if col in df.columns]
24
 
25
  # Define input and output interfaces
26
- inputs = [gr.Dataframe(headers=headers, row_count=(2, "dynamic"), col_count=(len(headers), "fixed"), label="Input Data", interactive=True)]
 
27
  outputs = [gr.Dataframe(row_count=(2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Depression"])]
28
 
 
 
 
 
 
29
  def infer(inputs):
30
  data = pd.DataFrame(inputs, columns=headers)
 
 
 
 
 
 
31
  predictions = pipe.predict(data)
32
  return pd.DataFrame(predictions, columns=["Depression"])
33
 
 
34
  gr.Interface(
35
  fn=infer,
36
  inputs=inputs,
 
23
  headers = [col for col in all_headers if col in df.columns]
24
 
25
  # Define input and output interfaces
26
+ #inputs = [gr.Dataframe(headers=headers, row_count=(2, "dynamic"), col_count=(len(headers), "fixed"), label="Input Data", interactive=True)]
27
+ inputs = [gr.Dataframe(headers=all_headers, row_count=(2, "dynamic"), col_count=(len(all_headers), "fixed"), label="Input Data", interactive=True)]
28
  outputs = [gr.Dataframe(row_count=(2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Depression"])]
29
 
30
+ #def infer(inputs):
31
+ #data = pd.DataFrame(inputs, columns=headers)
32
+ #predictions = pipe.predict(data)
33
+ #return pd.DataFrame(predictions, columns=["Depression"])
34
+
35
  def infer(inputs):
36
  data = pd.DataFrame(inputs, columns=headers)
37
+ # Add missing columns with default values (e.g., 0)
38
+ for col in all_headers:
39
+ if col not in data.columns:
40
+ data[col] = 0
41
+ # Ensure the order of columns matches the training data
42
+ data = data[all_headers]
43
  predictions = pipe.predict(data)
44
  return pd.DataFrame(predictions, columns=["Depression"])
45
 
46
+
47
  gr.Interface(
48
  fn=infer,
49
  inputs=inputs,