albertvillanova HF staff commited on
Commit
b1b50fb
1 Parent(s): 9ade1c2

Add Download button

Browse files
Files changed (2) hide show
  1. app.py +15 -0
  2. src/results.py +25 -0
app.py CHANGED
@@ -15,8 +15,10 @@ from src.details import (
15
  )
16
  from src.results import (
17
  clear_results,
 
18
  display_loading_message_for_results,
19
  display_results,
 
20
  fetch_result_paths,
21
  load_results_dataframes,
22
  plot_results,
@@ -69,6 +71,8 @@ with gr.Blocks(fill_height=True, fill_width=True, css=".col_heading {width: 50%}
69
  results = gr.HTML()
70
  results_dataframe_1 = gr.Dataframe(visible=False)
71
  results_dataframe_2 = gr.Dataframe(visible=False)
 
 
72
  with gr.Tab("Configs"):
73
  load_configs_btn = gr.Button("Load", interactive=False)
74
  clear_configs_btn = gr.Button("Clear")
@@ -161,6 +165,14 @@ with gr.Blocks(fill_height=True, fill_width=True, css=".col_heading {width: 50%}
161
  fn=plot_results,
162
  inputs=[results_task, results_dataframe_1, results_dataframe_2], # results,
163
  outputs=[results_plot_1, results_plot_2],
 
 
 
 
 
 
 
 
164
  )
165
  gr.on(
166
  triggers=[clear_results_btn.click, clear_configs_btn.click],
@@ -175,6 +187,9 @@ with gr.Blocks(fill_height=True, fill_width=True, css=".col_heading {width: 50%}
175
  results_task,
176
  configs_task,
177
  ],
 
 
 
178
  )
179
 
180
  # DETAILS:
 
15
  )
16
  from src.results import (
17
  clear_results,
18
+ clear_results_file,
19
  display_loading_message_for_results,
20
  display_results,
21
+ download_results,
22
  fetch_result_paths,
23
  load_results_dataframes,
24
  plot_results,
 
71
  results = gr.HTML()
72
  results_dataframe_1 = gr.Dataframe(visible=False)
73
  results_dataframe_2 = gr.Dataframe(visible=False)
74
+ download_results_btn = gr.Button("Download")
75
+ results_file = gr.File(visible=False)
76
  with gr.Tab("Configs"):
77
  load_configs_btn = gr.Button("Load", interactive=False)
78
  clear_configs_btn = gr.Button("Clear")
 
165
  fn=plot_results,
166
  inputs=[results_task, results_dataframe_1, results_dataframe_2], # results,
167
  outputs=[results_plot_1, results_plot_2],
168
+ ).then(
169
+ fn=clear_results_file,
170
+ outputs=results_file,
171
+ )
172
+ download_results_btn.click(
173
+ fn=download_results,
174
+ inputs=results,
175
+ outputs=results_file,
176
  )
177
  gr.on(
178
  triggers=[clear_results_btn.click, clear_configs_btn.click],
 
187
  results_task,
188
  configs_task,
189
  ],
190
+ ).then(
191
+ fn=clear_results_file,
192
+ outputs=results_file,
193
  )
194
 
195
  # DETAILS:
src/results.py CHANGED
@@ -1,4 +1,6 @@
1
  import asyncio
 
 
2
 
3
  import gradio as gr
4
  import pandas as pd
@@ -204,3 +206,26 @@ def plot_results(task, *dfs):
204
  return fig_1, fig_2
205
  else:
206
  return None, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import asyncio
2
+ import shutil
3
+ import tempfile
4
 
5
  import gradio as gr
6
  import pandas as pd
 
206
  return fig_1, fig_2
207
  else:
208
  return None, None
209
+
210
+
211
+ tmpdirname = None
212
+
213
+
214
+ def download_results(results):
215
+ global tmpdirname
216
+ if results:
217
+ if tmpdirname:
218
+ shutil.rmtree(tmpdirname)
219
+ tmpdirname = tempfile.mkdtemp()
220
+ path = f"{tmpdirname}/results.html"
221
+ with open(path, "w") as f:
222
+ f.write(results)
223
+ return gr.File(path, visible=True)
224
+
225
+
226
+ def clear_results_file():
227
+ global tmpdirname
228
+ if tmpdirname:
229
+ shutil.rmtree(tmpdirname)
230
+ tmpdirname = None
231
+ return gr.File(visible=False)