Spaces:
Sleeping
Sleeping
File size: 1,853 Bytes
222fbf0 edbcfa6 222fbf0 edbcfa6 c6a43c4 f072863 222fbf0 f072863 c6a43c4 f072863 c6a43c4 f072863 edbcfa6 f072863 edbcfa6 222fbf0 f072863 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import io
import gradio as gr
import os
import tempfile
def greet(
file_obj: tempfile._TemporaryFileWrapper,
col_to_fit: str,
niterations: int,
binary_operators: list,
unary_operators: list,
):
if col_to_fit == "":
raise ValueError("Please enter a column to predict")
niterations = int(niterations)
# Need to install PySR in separate python instance:
os.system(
"""if [ ! -d "$HOME/.julia/environments/pysr-0.9.1" ]
then
python -c 'import pysr; pysr.install()'
fi"""
)
from pysr import PySRRegressor
import numpy as np
import pandas as pd
df = pd.read_csv(file_obj.name)
y = np.array(df[col_to_fit])
X = df.drop([col_to_fit], axis=1)
model = PySRRegressor(
update=False,
temp_equation_file=True,
niterations=niterations,
binary_operators=binary_operators,
unary_operators=unary_operators,
)
model.fit(X, y)
return model.equations_
def main():
demo = gr.Interface(
fn=greet,
description="A demo of PySR",
inputs=[
gr.File(label="Upload a CSV file"),
gr.Textbox(placeholder="Column to predict"),
gr.Slider(
minimum=1,
maximum=1000,
value=40,
label="Number of iterations",
),
gr.CheckboxGroup(
choices=["+", "-", "*", "/", "^"],
label="Binary Operators",
value=["+", "-", "*", "/"],
),
gr.CheckboxGroup(
choices=["sin", "cos", "exp", "log"],
label="Unary Operators",
value=[],
),
],
outputs="dataframe",
)
# Add file to the demo:
demo.launch()
if __name__ == "__main__":
main()
|