Spaces:
Sleeping
Sleeping
Working app?
Browse files- gui/app.py +53 -19
gui/app.py
CHANGED
|
@@ -2,10 +2,18 @@ import io
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import tempfile
|
| 5 |
-
from typing import List
|
| 6 |
|
| 7 |
|
| 8 |
-
def greet(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Need to install PySR in separate python instance:
|
| 10 |
os.system(
|
| 11 |
"""if [ ! -d "$HOME/.julia/environments/pysr-0.9.1" ]
|
|
@@ -17,26 +25,52 @@ def greet(file_obj: List[tempfile._TemporaryFileWrapper]):
|
|
| 17 |
import numpy as np
|
| 18 |
import pandas as pd
|
| 19 |
|
| 20 |
-
df = pd.read_csv(file_obj
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
# df_output = model.equations_
|
| 28 |
-
df_output = df
|
| 29 |
-
df_output.to_csv("output.csv", index=False, sep="\t")
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
-
demo = gr.Interface(
|
| 35 |
-
fn=greet,
|
| 36 |
-
description="A demo of PySR",
|
| 37 |
-
inputs=gr.File(label="Upload a CSV file", file_count=1),
|
| 38 |
-
outputs=gr.File(label="Equation List"),
|
| 39 |
-
)
|
| 40 |
-
# Add file to the demo:
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import tempfile
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
+
def greet(
|
| 8 |
+
file_obj: tempfile._TemporaryFileWrapper,
|
| 9 |
+
col_to_fit: str,
|
| 10 |
+
niterations: int,
|
| 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(
|
| 19 |
"""if [ ! -d "$HOME/.julia/environments/pysr-0.9.1" ]
|
|
|
|
| 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])
|
| 30 |
+
X = df.drop([col_to_fit], axis=1)
|
| 31 |
|
| 32 |
+
model = PySRRegressor(
|
| 33 |
+
update=False,
|
| 34 |
+
temp_equation_file=True,
|
| 35 |
+
niterations=niterations,
|
| 36 |
+
binary_operators=binary_operators,
|
| 37 |
+
unary_operators=unary_operators,
|
| 38 |
+
)
|
| 39 |
+
model.fit(X, y)
|
| 40 |
+
|
| 41 |
+
return model.equations_
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
def main():
|
| 45 |
+
demo = gr.Interface(
|
| 46 |
+
fn=greet,
|
| 47 |
+
description="A demo of PySR",
|
| 48 |
+
inputs=[
|
| 49 |
+
gr.File(label="Upload a CSV file"),
|
| 50 |
+
gr.Textbox(placeholder="Column to predict"),
|
| 51 |
+
gr.Slider(
|
| 52 |
+
minimum=1,
|
| 53 |
+
maximum=1000,
|
| 54 |
+
value=40,
|
| 55 |
+
label="Number of iterations",
|
| 56 |
+
),
|
| 57 |
+
gr.CheckboxGroup(
|
| 58 |
+
choices=["+", "-", "*", "/", "^"],
|
| 59 |
+
label="Binary Operators",
|
| 60 |
+
value=["+", "-", "*", "/"],
|
| 61 |
+
),
|
| 62 |
+
gr.CheckboxGroup(
|
| 63 |
+
choices=["sin", "cos", "exp", "log"],
|
| 64 |
+
label="Unary Operators",
|
| 65 |
+
value=[],
|
| 66 |
+
),
|
| 67 |
+
],
|
| 68 |
+
outputs="dataframe",
|
| 69 |
+
)
|
| 70 |
+
# Add file to the demo:
|
| 71 |
|
| 72 |
+
demo.launch()
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
main()
|