MilesCranmer commited on
Commit
460af25
1 Parent(s): f072863

Output more useful errors

Browse files
Files changed (1) hide show
  1. gui/app.py +28 -5
gui/app.py CHANGED
@@ -2,6 +2,8 @@ import io
2
  import gradio as gr
3
  import os
4
  import tempfile
 
 
5
 
6
 
7
  def greet(
@@ -11,8 +13,28 @@ def greet(
11
  binary_operators: list,
12
  unary_operators: list,
13
  ):
 
 
 
 
 
 
 
14
  if col_to_fit == "":
15
- raise ValueError("Please enter a column to predict")
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  niterations = int(niterations)
17
  # Need to install PySR in separate python instance:
18
  os.system(
@@ -22,8 +44,6 @@ def greet(
22
  fi"""
23
  )
24
  from pysr import PySRRegressor
25
- import numpy as np
26
- import pandas as pd
27
 
28
  df = pd.read_csv(file_obj.name)
29
  y = np.array(df[col_to_fit])
@@ -38,7 +58,10 @@ def greet(
38
  )
39
  model.fit(X, y)
40
 
41
- return model.equations_
 
 
 
42
 
43
 
44
  def main():
@@ -65,7 +88,7 @@ def main():
65
  value=[],
66
  ),
67
  ],
68
- outputs="dataframe",
69
  )
70
  # Add file to the demo:
71
 
 
2
  import gradio as gr
3
  import os
4
  import tempfile
5
+ import numpy as np
6
+ import pandas as pd
7
 
8
 
9
  def greet(
 
13
  binary_operators: list,
14
  unary_operators: list,
15
  ):
16
+ empty_df = pd.DataFrame(
17
+ {
18
+ "equation": [],
19
+ "loss": [],
20
+ "complexity": [],
21
+ }
22
+ )
23
  if col_to_fit == "":
24
+ return (
25
+ empty_df,
26
+ "Please enter a column to predict!",
27
+ )
28
+ if len(binary_operators) == 0 and len(unary_operators) == 0:
29
+ return (
30
+ empty_df,
31
+ "Please select at least one operator!",
32
+ )
33
+ if file_obj is None:
34
+ return (
35
+ empty_df,
36
+ "Please upload a CSV file!",
37
+ )
38
  niterations = int(niterations)
39
  # Need to install PySR in separate python instance:
40
  os.system(
 
44
  fi"""
45
  )
46
  from pysr import PySRRegressor
 
 
47
 
48
  df = pd.read_csv(file_obj.name)
49
  y = np.array(df[col_to_fit])
 
58
  )
59
  model.fit(X, y)
60
 
61
+ df = model.equations_[["equation", "loss", "complexity"]]
62
+ # Convert all columns to string type:
63
+ df = df.astype(str)
64
+ return df, "Successful."
65
 
66
 
67
  def main():
 
88
  value=[],
89
  ),
90
  ],
91
+ outputs=["dataframe", "text"],
92
  )
93
  # Add file to the demo:
94