cgeorgiaw HF Staff commited on
Commit
5c8b9cf
·
1 Parent(s): 8bb5d86

adding more plot types

Browse files
Files changed (1) hide show
  1. app.py +37 -11
app.py CHANGED
@@ -26,9 +26,15 @@ def read_result_from_hub(filename):
26
  )
27
  return local_path
28
 
29
- def make_visual(boundary):
30
  boundary_plot = visualization.plot_boundary(boundary)
 
 
 
31
  interactive_plot = visualization.plot_surface(boundary)
 
 
 
32
  settings = forward_model.ConstellarationSettings.default_high_fidelity_skip_qi()
33
  boundary_metrics, boundary_equilibrium = forward_model.forward_model(
34
  boundary, settings=settings
@@ -37,10 +43,17 @@ def make_visual(boundary):
37
  boozer_plot = visualization.plot_boozer_surfaces(
38
  boundary_equilibrium, settings=boozer_settings
39
  )
 
 
 
 
 
 
 
40
  flux_surface_plot = visualization.plot_flux_surfaces(
41
  boundary_equilibrium, boundary
42
  )
43
- return boundary_plot, interactive_plot, boozer_plot, flux_surface_plot
44
 
45
  def gradio_interface() -> gr.Blocks:
46
  with gr.Blocks() as demo:
@@ -54,6 +67,8 @@ def gradio_interface() -> gr.Blocks:
54
  full_df = pd.DataFrame(ds)
55
  filenames = full_df['result_filename'].to_list()
56
 
 
 
57
  mode_selector = gr.Radio(choices=["Leaderboard", "Upload", "Generate"],
58
  label="Select input method:",
59
  value="Leaderboard")
@@ -95,11 +110,15 @@ def gradio_interface() -> gr.Blocks:
95
  else:
96
  boundary = load_boundary(row['boundary_json'])
97
 
98
- vis = make_visual(boundary)
99
- return vis
 
 
 
 
 
 
100
 
101
- dropdown.change(get_boundary_from_leaderboard, dropdown, [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
102
- rld_btn.click(get_boundary_from_leaderboard, dropdown, [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
103
 
104
  def get_boundary_vis_from_upload(uploaded_file):
105
  if uploaded_file is None:
@@ -107,18 +126,25 @@ def gradio_interface() -> gr.Blocks:
107
  with open(uploaded_file.name, 'r') as f:
108
  data = f.read()
109
  boundary = load_boundary(data)
110
- return make_visual(boundary)
111
 
112
- upload_box.change(get_boundary_vis_from_upload, inputs=[upload_box], outputs=[boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
 
 
 
 
113
 
114
  def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
115
  boundary = initial_guess.generate_rotating_ellipse(
116
  aspect_ratio=aspect_ratio, elongation=elongation, rotational_transform=rotational_transform, n_field_periods=n_field_periods
117
  )
118
- vis = make_visual(boundary)
119
- return vis
120
 
121
- generate_btn.click(generate_random_boundary, [aspect_ratio, elongation, rotational_transform, n_field_periods], [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
 
 
 
 
122
 
123
  return demo
124
 
 
26
  )
27
  return local_path
28
 
29
+ def make_boundary_plot(boundary):
30
  boundary_plot = visualization.plot_boundary(boundary)
31
+ return boundary_plot
32
+
33
+ def make_interactive_plot(boundary):
34
  interactive_plot = visualization.plot_surface(boundary)
35
+ return interactive_plot
36
+
37
+ def make_boozer_plot(boundary):
38
  settings = forward_model.ConstellarationSettings.default_high_fidelity_skip_qi()
39
  boundary_metrics, boundary_equilibrium = forward_model.forward_model(
40
  boundary, settings=settings
 
43
  boozer_plot = visualization.plot_boozer_surfaces(
44
  boundary_equilibrium, settings=boozer_settings
45
  )
46
+ return
47
+
48
+ def make_flux_surface_plot(boundary):
49
+ settings = forward_model.ConstellarationSettings.default_high_fidelity_skip_qi()
50
+ boundary_metrics, boundary_equilibrium = forward_model.forward_model(
51
+ boundary, settings=settings
52
+ )
53
  flux_surface_plot = visualization.plot_flux_surfaces(
54
  boundary_equilibrium, boundary
55
  )
56
+ return flux_surface_plot
57
 
58
  def gradio_interface() -> gr.Blocks:
59
  with gr.Blocks() as demo:
 
67
  full_df = pd.DataFrame(ds)
68
  filenames = full_df['result_filename'].to_list()
69
 
70
+ boundary = gr.State()
71
+
72
  mode_selector = gr.Radio(choices=["Leaderboard", "Upload", "Generate"],
73
  label="Select input method:",
74
  value="Leaderboard")
 
110
  else:
111
  boundary = load_boundary(row['boundary_json'])
112
 
113
+ return boundary
114
+
115
+ # dropdown.change(get_boundary_from_leaderboard, dropdown, [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
116
+ rld_btn.click(get_boundary_from_leaderboard, dropdown, boundary) \
117
+ .then(make_boundary_plot, boundary, boundary_plot) \
118
+ .then(make_interactive_plot, boundary, interactive_plot) \
119
+ .then(make_boozer_plot, boundary, boozer_plot) \
120
+ .then(make_flux_surface_plot, boundary, flux_surface_plot)
121
 
 
 
122
 
123
  def get_boundary_vis_from_upload(uploaded_file):
124
  if uploaded_file is None:
 
126
  with open(uploaded_file.name, 'r') as f:
127
  data = f.read()
128
  boundary = load_boundary(data)
129
+ return boundary
130
 
131
+ upload_box.change(get_boundary_vis_from_upload, inputs=[upload_box], outputs=boundary) \
132
+ .then(make_boundary_plot, boundary, boundary_plot) \
133
+ .then(make_interactive_plot, boundary, interactive_plot) \
134
+ .then(make_boozer_plot, boundary, boozer_plot) \
135
+ .then(make_flux_surface_plot, boundary, flux_surface_plot)
136
 
137
  def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
138
  boundary = initial_guess.generate_rotating_ellipse(
139
  aspect_ratio=aspect_ratio, elongation=elongation, rotational_transform=rotational_transform, n_field_periods=n_field_periods
140
  )
141
+ return boundary
 
142
 
143
+ generate_btn.click(generate_random_boundary, [aspect_ratio, elongation, rotational_transform, n_field_periods], boundary) \
144
+ .then(make_boundary_plot, boundary, boundary_plot) \
145
+ .then(make_interactive_plot, boundary, interactive_plot) \
146
+ .then(make_boozer_plot, boundary, boozer_plot) \
147
+ .then(make_flux_surface_plot, boundary, flux_surface_plot)
148
 
149
  return demo
150