Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
519fcb9
1
Parent(s):
9fa2182
Move more parts to other files
Browse files- gui/app.py +2 -2
- gui/data.py +22 -0
- gui/processing.py +6 -26
gui/app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
|
3 |
from .data import test_equations
|
4 |
from .plots import replot, replot_pareto
|
5 |
-
from .processing import
|
6 |
|
7 |
|
8 |
def _data_layout():
|
@@ -196,7 +196,7 @@ def main():
|
|
196 |
blocks["run"] = gr.Button()
|
197 |
|
198 |
blocks["run"].click(
|
199 |
-
|
200 |
inputs=[
|
201 |
blocks[k]
|
202 |
for k in [
|
|
|
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():
|
|
|
196 |
blocks["run"] = gr.Button()
|
197 |
|
198 |
blocks["run"].click(
|
199 |
+
processing,
|
200 |
inputs=[
|
201 |
blocks[k]
|
202 |
for k in [
|
gui/data.py
CHANGED
@@ -20,3 +20,25 @@ def generate_data(s: str, num_points: int, noise_level: float, data_seed: int):
|
|
20 |
noise = rstate.normal(0, noise_level, y.shape)
|
21 |
y_noisy = y + noise
|
22 |
return pd.DataFrame({"x": x}), y_noisy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
noise = rstate.normal(0, noise_level, y.shape)
|
21 |
y_noisy = y + noise
|
22 |
return pd.DataFrame({"x": x}), y_noisy
|
23 |
+
|
24 |
+
|
25 |
+
def read_csv(file_input: str, force_run: bool):
|
26 |
+
# Look at some statistics of the file:
|
27 |
+
df = pd.read_csv(file_input)
|
28 |
+
if len(df) == 0:
|
29 |
+
raise ValueError("The file is empty!")
|
30 |
+
if len(df.columns) == 1:
|
31 |
+
raise ValueError("The file has only one column!")
|
32 |
+
if len(df) > 10_000 and not force_run:
|
33 |
+
raise ValueError(
|
34 |
+
"You have uploaded a file with more than 10,000 rows. "
|
35 |
+
"This will take very long to run. "
|
36 |
+
"Please upload a subsample of the data, "
|
37 |
+
"or check the box 'Ignore Warnings'.",
|
38 |
+
)
|
39 |
+
|
40 |
+
col_to_fit = df.columns[-1]
|
41 |
+
y = np.array(df[col_to_fit])
|
42 |
+
X = df.drop([col_to_fit], axis=1)
|
43 |
+
|
44 |
+
return X, y
|
gui/processing.py
CHANGED
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
|
10 |
-
from .data import generate_data
|
11 |
|
12 |
EMPTY_DF = lambda: pd.DataFrame(
|
13 |
{
|
@@ -18,7 +18,7 @@ EMPTY_DF = lambda: pd.DataFrame(
|
|
18 |
)
|
19 |
|
20 |
|
21 |
-
def
|
22 |
file_input,
|
23 |
force_run,
|
24 |
test_equation,
|
@@ -43,30 +43,10 @@ def process(
|
|
43 |
):
|
44 |
"""Load data, then spawn a process to run the greet function."""
|
45 |
if file_input is not None:
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
return (
|
50 |
-
EMPTY_DF(),
|
51 |
-
"The file is empty!",
|
52 |
-
)
|
53 |
-
if len(df.columns) == 1:
|
54 |
-
return (
|
55 |
-
EMPTY_DF(),
|
56 |
-
"The file has only one column!",
|
57 |
-
)
|
58 |
-
if len(df) > 10_000 and not force_run:
|
59 |
-
return (
|
60 |
-
EMPTY_DF(),
|
61 |
-
"You have uploaded a file with more than 10,000 rows. "
|
62 |
-
"This will take very long to run. "
|
63 |
-
"Please upload a subsample of the data, "
|
64 |
-
"or check the box 'Ignore Warnings'.",
|
65 |
-
)
|
66 |
-
|
67 |
-
col_to_fit = df.columns[-1]
|
68 |
-
y = np.array(df[col_to_fit])
|
69 |
-
X = df.drop([col_to_fit], axis=1)
|
70 |
else:
|
71 |
X, y = generate_data(test_equation, num_points, noise_level, data_seed)
|
72 |
|
|
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
|
10 |
+
from .data import generate_data, read_csv
|
11 |
|
12 |
EMPTY_DF = lambda: pd.DataFrame(
|
13 |
{
|
|
|
18 |
)
|
19 |
|
20 |
|
21 |
+
def processing(
|
22 |
file_input,
|
23 |
force_run,
|
24 |
test_equation,
|
|
|
43 |
):
|
44 |
"""Load data, then spawn a process to run the greet function."""
|
45 |
if file_input is not None:
|
46 |
+
try:
|
47 |
+
X, y = read_csv(file_input, force_run)
|
48 |
+
except ValueError as e:
|
49 |
+
return (EMPTY_DF(), str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
else:
|
51 |
X, y = generate_data(test_equation, num_points, noise_level, data_seed)
|
52 |
|