adding upload option
Browse files
app.py
CHANGED
@@ -51,6 +51,9 @@ def gradio_interface() -> gr.Blocks:
|
|
51 |
with gr.Column(visible=True) as leaderboard_ui:
|
52 |
dropdown = gr.Dropdown(choices=filenames, label="Choose a leaderboard entry", value=filenames[0])
|
53 |
rld_btn = gr.Button(value="Reload")
|
|
|
|
|
|
|
54 |
|
55 |
with gr.Column(visible=False) as generate_ui:
|
56 |
aspect_ratio = gr.Number(label="Aspect Ratio", value=3)
|
@@ -65,10 +68,11 @@ def gradio_interface() -> gr.Blocks:
|
|
65 |
def update_ui(mode):
|
66 |
return (
|
67 |
gr.update(visible=(mode == "Leaderboard")),
|
|
|
68 |
gr.update(visible=(mode == "Generate")),
|
69 |
)
|
70 |
|
71 |
-
mode_selector.change(update_ui, inputs=[mode_selector], outputs=[leaderboard_ui, generate_ui])
|
72 |
|
73 |
def get_boundary_from_leaderboard(selected_file):
|
74 |
row = full_df[full_df['result_filename'] == selected_file].iloc[0]
|
@@ -82,7 +86,17 @@ def gradio_interface() -> gr.Blocks:
|
|
82 |
|
83 |
dropdown.change(get_boundary_from_leaderboard, dropdown, plot)
|
84 |
rld_btn.click(get_boundary_from_leaderboard, dropdown, plot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
|
|
|
|
86 |
def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
|
87 |
boundary = initial_guess.generate_rotating_ellipse(
|
88 |
aspect_ratio=aspect_ratio, elongation=elongation, rotational_transform=rotational_transform, n_field_periods=n_field_periods
|
|
|
51 |
with gr.Column(visible=True) as leaderboard_ui:
|
52 |
dropdown = gr.Dropdown(choices=filenames, label="Choose a leaderboard entry", value=filenames[0])
|
53 |
rld_btn = gr.Button(value="Reload")
|
54 |
+
|
55 |
+
with gr.Column(visible=False) as upload_ui:
|
56 |
+
upload_box = gr.File(file_types=[".json"], label="Upload your boundary file")
|
57 |
|
58 |
with gr.Column(visible=False) as generate_ui:
|
59 |
aspect_ratio = gr.Number(label="Aspect Ratio", value=3)
|
|
|
68 |
def update_ui(mode):
|
69 |
return (
|
70 |
gr.update(visible=(mode == "Leaderboard")),
|
71 |
+
gr.update(visible=(mode == "Upload")),
|
72 |
gr.update(visible=(mode == "Generate")),
|
73 |
)
|
74 |
|
75 |
+
mode_selector.change(update_ui, inputs=[mode_selector], outputs=[leaderboard_ui, upload_ui, generate_ui])
|
76 |
|
77 |
def get_boundary_from_leaderboard(selected_file):
|
78 |
row = full_df[full_df['result_filename'] == selected_file].iloc[0]
|
|
|
86 |
|
87 |
dropdown.change(get_boundary_from_leaderboard, dropdown, plot)
|
88 |
rld_btn.click(get_boundary_from_leaderboard, dropdown, plot)
|
89 |
+
|
90 |
+
def get_boundary_vis_from_upload(uploaded_file):
|
91 |
+
if uploaded_file is None:
|
92 |
+
raise gr.Error("Please upload a file.")
|
93 |
+
with open(uploaded_file.name, 'r') as f:
|
94 |
+
data = json.load(f)
|
95 |
+
boundary = load_boundary(data)
|
96 |
+
return make_visual(boundary)
|
97 |
|
98 |
+
upload_box.change(get_boundary_vis_from_upload, inputs=[upload_box], outputs=[plot])
|
99 |
+
|
100 |
def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
|
101 |
boundary = initial_guess.generate_rotating_ellipse(
|
102 |
aspect_ratio=aspect_ratio, elongation=elongation, rotational_transform=rotational_transform, n_field_periods=n_field_periods
|