File size: 2,082 Bytes
222fbf0
edbcfa6
222fbf0
460af25
edbcfa6
71ed397
 
 
 
 
 
 
c6a43c4
f072863
 
 
 
 
 
 
 
460af25
 
 
 
 
 
 
 
 
 
 
 
 
 
f072863
ad955c1
 
 
 
 
c6a43c4
 
f072863
 
 
dc554ea
f072863
8614da9
 
 
f072863
 
454ec0a
f072863
 
8614da9
f072863
 
454ec0a
f072863
8614da9
f072863
 
454ec0a
f072863
 
8614da9
454ec0a
 
8614da9
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
78
79
80
import gradio as gr
import os
import tempfile
import pandas as pd

empty_df = pd.DataFrame(
    {
        "equation": [],
        "loss": [],
        "complexity": [],
    }
)

def greet(
    file_obj: tempfile._TemporaryFileWrapper,
    col_to_fit: str,
    niterations: int,
    binary_operators: list,
    unary_operators: list,
):
    if col_to_fit == "":
        return (
            empty_df,
            "Please enter a column to predict!",
        )
    if len(binary_operators) == 0 and len(unary_operators) == 0:
        return (
            empty_df,
            "Please select at least one operator!",
        )
    if file_obj is None:
        return (
            empty_df,
            "Please upload a CSV file!",
        )

    os.system("bash install_pysr.sh")
    os.system(f"python run_pysr_and_save.py --niterations {niterations} --binary_operators '{binary_operators}' --unary_operators '{unary_operators}' --col_to_fit {col_to_fit} --filename {file_obj.name}")
    df = pd.read_csv("pysr_output.csv")
    error_log = open("error.log", "r").read()
    return df, error_log


def main():
    demo = gr.Interface(
        fn=greet,
        description="PySR Demo",
        inputs=[
            gr.inputs.File(label="Upload a CSV File"),
            gr.inputs.Textbox(label="Column to Predict", placeholder="y"),
            gr.inputs.Slider(
                minimum=1,
                maximum=1000,
                default=40,
                label="Number of iterations",
            ),
            gr.inputs.CheckboxGroup(
                choices=["+", "-", "*", "/", "^"],
                label="Binary Operators",
                default=["+", "-", "*", "/"],
            ),
            gr.inputs.CheckboxGroup(
                choices=["sin", "cos", "exp", "log"],
                label="Unary Operators",
                default=[],
            ),
        ],
        outputs=[
            "dataframe",
            gr.outputs.Textbox(label="Error Log"),
        ],
    )
    # Add file to the demo:

    demo.launch()


if __name__ == "__main__":
    main()