Spaces:
Running
Running
MilesCranmer
commited on
Commit
β’
86e9755
1
Parent(s):
519fcb9
Integrate gui in main codebase
Browse files- pysr/_cli/main.py +6 -0
- {gui β pysr/gui}/app.py +12 -6
- {gui β pysr/gui}/data.py +0 -0
- {gui β pysr/gui}/plots.py +21 -10
- {gui β pysr/gui}/processing.py +0 -0
- gui/requirements.txt β requirements-gui.txt +0 -0
pysr/_cli/main.py
CHANGED
@@ -5,6 +5,7 @@ import warnings
|
|
5 |
|
6 |
import click
|
7 |
|
|
|
8 |
from ..test import (
|
9 |
get_runtests_cli,
|
10 |
runtests,
|
@@ -48,6 +49,11 @@ def _install(julia_project, quiet, precompile):
|
|
48 |
)
|
49 |
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
TEST_OPTIONS = {"main", "jax", "torch", "cli", "dev", "startup"}
|
52 |
|
53 |
|
|
|
5 |
|
6 |
import click
|
7 |
|
8 |
+
from ..gui import main as gui_main
|
9 |
from ..test import (
|
10 |
get_runtests_cli,
|
11 |
runtests,
|
|
|
49 |
)
|
50 |
|
51 |
|
52 |
+
@pysr.command("gui", help="Start a Gradio-based GUI.")
|
53 |
+
def _gui():
|
54 |
+
gui_main()
|
55 |
+
|
56 |
+
|
57 |
TEST_OPTIONS = {"main", "jax", "torch", "cli", "dev", "startup"}
|
58 |
|
59 |
|
{gui β pysr/gui}/app.py
RENAMED
@@ -1,11 +1,17 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
from .data import test_equations
|
4 |
from .plots import replot, replot_pareto
|
5 |
from .processing import processing
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def _data_layout():
|
|
|
|
|
9 |
with gr.Tab("Example Data"):
|
10 |
# Plot of the example data:
|
11 |
with gr.Row():
|
@@ -43,6 +49,8 @@ def _data_layout():
|
|
43 |
|
44 |
|
45 |
def _settings_layout():
|
|
|
|
|
46 |
with gr.Tab("Basic Settings"):
|
47 |
binary_operators = gr.CheckboxGroup(
|
48 |
choices=["+", "-", "*", "/", "^", "max", "min", "mod", "cond"],
|
@@ -171,6 +179,8 @@ def _settings_layout():
|
|
171 |
|
172 |
|
173 |
def main():
|
|
|
|
|
174 |
blocks = {}
|
175 |
with gr.Blocks() as demo:
|
176 |
with gr.Row():
|
@@ -245,7 +255,3 @@ def main():
|
|
245 |
demo.load(replot, eqn_components, blocks["example_plot"])
|
246 |
|
247 |
demo.launch(debug=True)
|
248 |
-
|
249 |
-
|
250 |
-
if __name__ == "__main__":
|
251 |
-
main()
|
|
|
|
|
|
|
1 |
from .data import test_equations
|
2 |
from .plots import replot, replot_pareto
|
3 |
from .processing import processing
|
4 |
|
5 |
|
6 |
+
def get_gr():
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
return gr
|
10 |
+
|
11 |
+
|
12 |
def _data_layout():
|
13 |
+
gr = get_gr()
|
14 |
+
|
15 |
with gr.Tab("Example Data"):
|
16 |
# Plot of the example data:
|
17 |
with gr.Row():
|
|
|
49 |
|
50 |
|
51 |
def _settings_layout():
|
52 |
+
gr = get_gr()
|
53 |
+
|
54 |
with gr.Tab("Basic Settings"):
|
55 |
binary_operators = gr.CheckboxGroup(
|
56 |
choices=["+", "-", "*", "/", "^", "max", "min", "mod", "cond"],
|
|
|
179 |
|
180 |
|
181 |
def main():
|
182 |
+
gr = get_gr()
|
183 |
+
|
184 |
blocks = {}
|
185 |
with gr.Blocks() as demo:
|
186 |
with gr.Row():
|
|
|
255 |
demo.load(replot, eqn_components, blocks["example_plot"])
|
256 |
|
257 |
demo.launch(debug=True)
|
|
|
|
|
|
|
|
{gui β pysr/gui}/data.py
RENAMED
File without changes
|
{gui β pysr/gui}/plots.py
RENAMED
@@ -1,20 +1,30 @@
|
|
1 |
import numpy as np
|
2 |
import pandas as pd
|
3 |
-
from matplotlib import pyplot as plt
|
4 |
-
|
5 |
-
plt.ioff()
|
6 |
-
plt.rcParams["font.family"] = [
|
7 |
-
"IBM Plex Mono",
|
8 |
-
# Fallback fonts:
|
9 |
-
"DejaVu Sans Mono",
|
10 |
-
"Courier New",
|
11 |
-
"monospace",
|
12 |
-
]
|
13 |
|
14 |
from .data import generate_data
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def replot_pareto(df: pd.DataFrame, maxsize: int):
|
|
|
18 |
fig, ax = plt.subplots(figsize=(6, 6), dpi=100)
|
19 |
|
20 |
if len(df) == 0 or "Equation" not in df.columns:
|
@@ -60,6 +70,7 @@ def replot(test_equation, num_points, noise_level, data_seed):
|
|
60 |
X, y = generate_data(test_equation, num_points, noise_level, data_seed)
|
61 |
x = X["x"]
|
62 |
|
|
|
63 |
plt.rcParams["font.family"] = "IBM Plex Mono"
|
64 |
fig, ax = plt.subplots(figsize=(6, 6), dpi=100)
|
65 |
|
|
|
1 |
import numpy as np
|
2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
from .data import generate_data
|
5 |
|
6 |
+
FIRST_LOAD = True
|
7 |
+
|
8 |
+
|
9 |
+
def get_plt():
|
10 |
+
from matplotlib import pyplot as plt
|
11 |
+
|
12 |
+
if FIRST_LOAD:
|
13 |
+
plt.ioff()
|
14 |
+
plt.rcParams["font.family"] = [
|
15 |
+
"IBM Plex Mono",
|
16 |
+
# Fallback fonts:
|
17 |
+
"DejaVu Sans Mono",
|
18 |
+
"Courier New",
|
19 |
+
"monospace",
|
20 |
+
]
|
21 |
+
|
22 |
+
FIRST_LOAD = False
|
23 |
+
return plt
|
24 |
+
|
25 |
|
26 |
def replot_pareto(df: pd.DataFrame, maxsize: int):
|
27 |
+
plt = get_plt()
|
28 |
fig, ax = plt.subplots(figsize=(6, 6), dpi=100)
|
29 |
|
30 |
if len(df) == 0 or "Equation" not in df.columns:
|
|
|
70 |
X, y = generate_data(test_equation, num_points, noise_level, data_seed)
|
71 |
x = X["x"]
|
72 |
|
73 |
+
plt = get_plt()
|
74 |
plt.rcParams["font.family"] = "IBM Plex Mono"
|
75 |
fig, ax = plt.subplots(figsize=(6, 6), dpi=100)
|
76 |
|
{gui β pysr/gui}/processing.py
RENAMED
File without changes
|
gui/requirements.txt β requirements-gui.txt
RENAMED
File without changes
|