jerome-white commited on
Commit
5f3872f
1 Parent(s): 1900305

Push the HDI input after the model selection

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -163,12 +163,28 @@ class ComparisonPlotter(DataPlotter):
163
  except ArithmeticError:
164
  pass
165
 
166
- def cplot(df):
167
- def _plot(model_1, model_2, ci):
168
- cp = ComparisonPlotter(df, model_1, model_2, ci)
 
 
 
 
169
  return cp.plot()
170
 
171
- return _plot
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  #
174
  #
@@ -231,19 +247,10 @@ def layout(tab):
231
 
232
  ''')
233
  with gr.Column():
234
- models = df['model'].unique()
235
- choices = sorted(models, key=lambda x: x.lower())
236
- partial = ft.partial(gr.Dropdown, choices=choices)
237
- drops = (partial(label=f'Model {x}') for x in range(1, 3))
238
-
239
- ci = gr.Number(value=0.95, minimum=0, maximum=1, step=1e-2)
240
-
241
- inputs = [
242
- *drops,
243
- ci,
244
- ]
245
  button = gr.Button(value='Compare!')
246
- button.click(cplot(df), inputs=inputs, outputs=[display])
247
 
248
  with gr.Accordion('Disclaimer', open=False):
249
  gr.Markdown(docs['disclaimer'])
 
163
  except ArithmeticError:
164
  pass
165
 
166
+ class ComparisonMenu:
167
+ def __init__(self, df, ci=0.95):
168
+ self.df = df
169
+ self.ci = ci
170
+
171
+ def __call__(self, model_1, model_2, ci):
172
+ cp = ComparisonPlotter(self.df, model_1, model_2, ci)
173
  return cp.plot()
174
 
175
+ def build_and_get(self):
176
+ models = self.df['model'].unique()
177
+ choices = sorted(models, key=lambda x: x.lower())
178
+
179
+ for i in range(1, 3):
180
+ label = f'Model {i}'
181
+ yield gr.Dropdown(label=label, choices=choices)
182
+
183
+ yield gr.Number(value=self.ci,
184
+ label='HDI',
185
+ minimum=0,
186
+ maximum=1,
187
+ step=1e-2)
188
 
189
  #
190
  #
 
247
 
248
  ''')
249
  with gr.Column():
250
+ menu = ComparisonMenu(df)
251
+ inputs = list(menu.build_and_get())
 
 
 
 
 
 
 
 
 
252
  button = gr.Button(value='Compare!')
253
+ button.click(menu, inputs=inputs, outputs=[display])
254
 
255
  with gr.Accordion('Disclaimer', open=False):
256
  gr.Markdown(docs['disclaimer'])