Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
222fbf0
1
Parent(s):
9cee10c
Init gradio version
Browse files- gui/app.py +34 -34
gui/app.py
CHANGED
@@ -1,42 +1,42 @@
|
|
1 |
-
import
|
|
|
2 |
import os
|
|
|
|
|
3 |
|
4 |
-
# Need to install PySR in separate python instance:
|
5 |
-
os.system(
|
6 |
-
"""
|
7 |
-
if [ ! -d "$HOME/.julia/environments/pysr-0.9.1" ]; then
|
8 |
-
python -c 'import pysr; pysr.install()'
|
9 |
-
fi
|
10 |
-
"""
|
11 |
-
)
|
12 |
-
import pysr
|
13 |
-
from pysr import PySRRegressor
|
14 |
-
import numpy as np
|
15 |
-
import pandas as pd
|
16 |
-
|
17 |
-
st.title("Interactive PySR")
|
18 |
-
file_name = st.file_uploader(
|
19 |
-
"Upload a data file, with your output column labeled 'y'", type=["csv"]
|
20 |
-
)
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
X = df.drop(["y"], axis=1)
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
col2.header("Loss")
|
34 |
-
for i, row in model.equations_.iterrows():
|
35 |
-
col1.subheader(str(row["equation"]))
|
36 |
-
col2.subheader(str(row["loss"]))
|
37 |
|
38 |
-
model = None
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import gradio as gr
|
3 |
import os
|
4 |
+
import tempfile
|
5 |
+
from typing import List
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def greet(file_obj: List[tempfile._TemporaryFileWrapper]):
|
9 |
+
# Need to install PySR in separate python instance:
|
10 |
+
os.system(
|
11 |
+
"""if [ ! -d "$HOME/.julia/environments/pysr-0.9.1" ]
|
12 |
+
then
|
13 |
+
python -c 'import pysr; pysr.install()'
|
14 |
+
fi"""
|
15 |
+
)
|
16 |
+
from pysr import PySRRegressor
|
17 |
+
import numpy as np
|
18 |
+
import pandas as pd
|
19 |
+
|
20 |
+
df = pd.read_csv(file_obj[0])
|
21 |
+
# y = np.array(df["y"])
|
22 |
+
# X = df.drop(["y"], axis=1)
|
23 |
|
24 |
+
# model = PySRRegressor(update=False, temp_equation_file=True)
|
25 |
+
# model.fit(X, y)
|
|
|
26 |
|
27 |
+
# df_output = model.equations_
|
28 |
+
df_output = df
|
29 |
+
df_output.to_csv("output.csv", index=False, sep="\t")
|
30 |
|
31 |
+
return "output.csv"
|
|
|
|
|
|
|
|
|
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 |
+
demo.launch()
|