Spaces:
Sleeping
Sleeping
Lennard Schober
commited on
Commit
·
08bc7ab
1
Parent(s):
e581117
Add quality settings
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ glob_a = -2.0
|
|
| 11 |
glob_b = 4.0
|
| 12 |
glob_c = 7.5
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
def clear_npz():
|
| 16 |
current_directory = os.getcwd() # Get the current working directory
|
|
@@ -37,10 +38,7 @@ def complex_heat_eq_solution(x, t, k, a, b, c):
|
|
| 37 |
|
| 38 |
|
| 39 |
def plot_heat_equation(m, approx_type):
|
| 40 |
-
global glob_k, glob_a, glob_b, glob_c
|
| 41 |
-
# Define grid dimensions
|
| 42 |
-
n_x = 32 # Fixed spatial grid resolution
|
| 43 |
-
n_t = 50
|
| 44 |
|
| 45 |
try:
|
| 46 |
loaded_values = np.load(f"{approx_type}_m{m}.npz")
|
|
@@ -156,9 +154,7 @@ def plot_heat_equation(m, approx_type):
|
|
| 156 |
|
| 157 |
|
| 158 |
def plot_errors(m, approx_type):
|
| 159 |
-
|
| 160 |
-
n_x = 32 # Fixed spatial grid resolution
|
| 161 |
-
n_t = 50
|
| 162 |
|
| 163 |
try:
|
| 164 |
loaded_values = np.load(f"{approx_type}_m{m}.npz")
|
|
@@ -261,8 +257,8 @@ def plot_errors(m, approx_type):
|
|
| 261 |
return fig
|
| 262 |
|
| 263 |
|
| 264 |
-
def generate_data(
|
| 265 |
-
global glob_k, glob_a, glob_b, glob_c
|
| 266 |
"""Generate training data."""
|
| 267 |
x = np.linspace(0, 1, n_x) # spatial points
|
| 268 |
t = np.linspace(0, 5, n_t) # temporal points
|
|
@@ -323,13 +319,12 @@ def polyfit2d(x, y, z, kx=3, ky=3, order=None):
|
|
| 323 |
|
| 324 |
|
| 325 |
def train_coefficients(m, kernel):
|
| 326 |
-
global glob_k, glob_a, glob_b, glob_c
|
| 327 |
# Start time for training
|
| 328 |
start_time = time.time()
|
| 329 |
|
| 330 |
# Generate data
|
| 331 |
-
|
| 332 |
-
a_train, u_train, x, t = generate_data(n_x, n_t)
|
| 333 |
|
| 334 |
print("in train coeffs: ", glob_k)
|
| 335 |
|
|
@@ -441,6 +436,16 @@ def plot_all(m, kernel):
|
|
| 441 |
gr.update(visible=True, value=error_fig),
|
| 442 |
)
|
| 443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
|
| 445 |
# Gradio interface
|
| 446 |
def create_gradio_ui():
|
|
@@ -500,6 +505,10 @@ def create_gradio_ui():
|
|
| 500 |
with gr.Column():
|
| 501 |
with gr.Row():
|
| 502 |
# Kernel selection and slider for m
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
kernel_dropdown = gr.Dropdown(
|
| 504 |
label="Choose Kernel", choices=["SINE", "GFF"], value="SINE"
|
| 505 |
)
|
|
@@ -508,7 +517,6 @@ def create_gradio_ui():
|
|
| 508 |
choices=[50, 250, 1000, 5000, 10000, 25000],
|
| 509 |
value=1000,
|
| 510 |
)
|
| 511 |
-
|
| 512 |
# Output to show status
|
| 513 |
output = gr.Textbox(label="Status", interactive=False)
|
| 514 |
|
|
|
|
| 11 |
glob_b = 4.0
|
| 12 |
glob_c = 7.5
|
| 13 |
|
| 14 |
+
n_x, n_t = 10, 10
|
| 15 |
|
| 16 |
def clear_npz():
|
| 17 |
current_directory = os.getcwd() # Get the current working directory
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def plot_heat_equation(m, approx_type):
|
| 41 |
+
global glob_k, glob_a, glob_b, glob_c, n_x, n_t
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
try:
|
| 44 |
loaded_values = np.load(f"{approx_type}_m{m}.npz")
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
def plot_errors(m, approx_type):
|
| 157 |
+
global n_x, n_t
|
|
|
|
|
|
|
| 158 |
|
| 159 |
try:
|
| 160 |
loaded_values = np.load(f"{approx_type}_m{m}.npz")
|
|
|
|
| 257 |
return fig
|
| 258 |
|
| 259 |
|
| 260 |
+
def generate_data():
|
| 261 |
+
global glob_k, glob_a, glob_b, glob_c, n_x, n_t
|
| 262 |
"""Generate training data."""
|
| 263 |
x = np.linspace(0, 1, n_x) # spatial points
|
| 264 |
t = np.linspace(0, 5, n_t) # temporal points
|
|
|
|
| 319 |
|
| 320 |
|
| 321 |
def train_coefficients(m, kernel):
|
| 322 |
+
global glob_k, glob_a, glob_b, glob_c, n_x, n_t
|
| 323 |
# Start time for training
|
| 324 |
start_time = time.time()
|
| 325 |
|
| 326 |
# Generate data
|
| 327 |
+
a_train, u_train, x, t = generate_data()
|
|
|
|
| 328 |
|
| 329 |
print("in train coeffs: ", glob_k)
|
| 330 |
|
|
|
|
| 436 |
gr.update(visible=True, value=error_fig),
|
| 437 |
)
|
| 438 |
|
| 439 |
+
def change_quality(quality):
|
| 440 |
+
global n_x, n_t
|
| 441 |
+
|
| 442 |
+
if quality == "Low":
|
| 443 |
+
n_x, n_t = 10, 10
|
| 444 |
+
elif quality == "Mid":
|
| 445 |
+
n_x, n_t = 20, 20
|
| 446 |
+
elif quality == "High":
|
| 447 |
+
n_x, n_t = 40, 40
|
| 448 |
+
|
| 449 |
|
| 450 |
# Gradio interface
|
| 451 |
def create_gradio_ui():
|
|
|
|
| 505 |
with gr.Column():
|
| 506 |
with gr.Row():
|
| 507 |
# Kernel selection and slider for m
|
| 508 |
+
quality_dropdown = gr.Dropdown(
|
| 509 |
+
label="Choose Quality", choices=["Low", "Mid", "High"], value="Low"
|
| 510 |
+
)
|
| 511 |
+
quality_dropdown.change(fn=change_quality, inputs=quality_dropdown, outputs=None)
|
| 512 |
kernel_dropdown = gr.Dropdown(
|
| 513 |
label="Choose Kernel", choices=["SINE", "GFF"], value="SINE"
|
| 514 |
)
|
|
|
|
| 517 |
choices=[50, 250, 1000, 5000, 10000, 25000],
|
| 518 |
value=1000,
|
| 519 |
)
|
|
|
|
| 520 |
# Output to show status
|
| 521 |
output = gr.Textbox(label="Status", interactive=False)
|
| 522 |
|