FrankWanger commited on
Commit
51b03b4
·
1 Parent(s): 5d0bd6e

changed to gr_blocks dev

Browse files
Files changed (1) hide show
  1. app.py +54 -8
app.py CHANGED
@@ -183,6 +183,11 @@ def predict(text1, conc1, flow_rate1, voltage1, solvent1, text2, conc2, flow_rat
183
 
184
  return (gr_exp_record_df, gr.DataFrame(value=results_display, label="Your Results"), plot_results(results_storage))
185
 
 
 
 
 
 
186
  inputs = [
187
  gr.Markdown("### Experiment 1"),
188
  gr.Number(value=1.2, label="Concentration (%w/v, range: 0.05-5.00)", minimum=0.05, maximum=5.0, precision=3),
@@ -200,12 +205,53 @@ outputs = [gr_exp_record_df, gr.DataFrame(label="Your Results"), gr.Plot(label="
200
 
201
  description = "<h3>Welcome, challenger!</h3><p> If you think you may perform better than <strong>CCBO</strong>, try this interactive game to optimize electrospray! Rules are simple: <ul><li>Examine carefully the initial experiments you have on the right (or below if you're using your phone), remember, your target size is <u><i><strong>3.000 um</strong></i></u> ----></li><li>Select your parameters, you have <strong>2</strong> experiments (chances) in each round, use them wisely! </li><li>Click <strong>Submit</strong> to see the results, reflect and improve your selection!</li><li>Repeat the process for <strong>5</strong> rounds to see if you can beat CCBO!</li></ul></p>"
202
 
203
- # Update interface
204
- demo = gr.Interface(
205
- fn=predict,
206
- inputs=inputs,
207
- outputs=outputs,
208
- title="Human vs CCBO Campaign - Simulated Electrospray",
209
- description=description
210
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  demo.launch()
 
183
 
184
  return (gr_exp_record_df, gr.DataFrame(value=results_display, label="Your Results"), plot_results(results_storage))
185
 
186
+ def reset_results():
187
+ global results_storage
188
+ results_storage = pd.DataFrame(columns=['Concentration (%w/v)', 'Flow Rate (mL/h)', 'Voltage (kV)', 'Solvent', 'Size (um)', 'Feasible?'])
189
+ return (gr_exp_record_df, gr.DataFrame(value=results_storage.style.map(highlight_success, subset=['Feasible?']).format(precision=3), label="Your Results"), plot_results(results_storage))
190
+
191
  inputs = [
192
  gr.Markdown("### Experiment 1"),
193
  gr.Number(value=1.2, label="Concentration (%w/v, range: 0.05-5.00)", minimum=0.05, maximum=5.0, precision=3),
 
205
 
206
  description = "<h3>Welcome, challenger!</h3><p> If you think you may perform better than <strong>CCBO</strong>, try this interactive game to optimize electrospray! Rules are simple: <ul><li>Examine carefully the initial experiments you have on the right (or below if you're using your phone), remember, your target size is <u><i><strong>3.000 um</strong></i></u> ----></li><li>Select your parameters, you have <strong>2</strong> experiments (chances) in each round, use them wisely! </li><li>Click <strong>Submit</strong> to see the results, reflect and improve your selection!</li><li>Repeat the process for <strong>5</strong> rounds to see if you can beat CCBO!</li></ul></p>"
207
 
208
+ # Create a Blocks interface instead of using Interface
209
+ with gr.Blocks() as demo:
210
+
211
+ gr.Markdown("## Human vs CCBO Campaign - Simulated Electrospray")
212
+ gr.Markdown(description)
213
+ with gr.Row():
214
+ with gr.Column():
215
+ gr.Markdown("### Experiment 1")
216
+ conc1 = gr.Number(value=1.2, label="Concentration (%w/v, range: 0.05-5.00)", minimum=0.05, maximum=5.0, precision=3)
217
+ flow_rate1 = gr.Number(value=20.0, label="Flow Rate (mL/h, range: 0.01-60.00)", minimum=0.01, maximum=60.0, precision=3)
218
+ voltage1 = gr.Number(value=15.0, label="Voltage (kV, range: 10.00-18.00)", minimum=10.0, maximum=18.0, precision=3)
219
+ solvent1 = gr.Dropdown(['DMAc', 'CHCl3'], value='DMAc', label='Solvent')
220
+
221
+ gr.Markdown("### Experiment 2")
222
+ conc2 = gr.Number(value=2.8, label="Concentration (%w/v, range: 0.05-5.00)", minimum=0.05, maximum=5.0, precision=3)
223
+ flow_rate2 = gr.Number(value=20.0, label="Flow Rate (mL/h, range: 0.01-60.00)", minimum=0.01, maximum=60.0, precision=3)
224
+ voltage2 = gr.Number(value=15.0, label="Voltage (kV, 10.00-18.00)", minimum=10.0, maximum=18.0, precision=3)
225
+ solvent2 = gr.Dropdown(['DMAc', 'CHCl3'], value='CHCl3', label='Solvent')
226
+
227
+ with gr.Column():
228
+ prior_experiments = gr.DataFrame(value=exp_record_df.style.map(highlight_success, subset=['Feasible?']).format(precision=3), label="Prior Experiments")
229
+ results_df = gr.DataFrame(label="Your Results")
230
+ perf_plot = gr.Plot(label="Performance Comparison")
231
+
232
+ with gr.Row():
233
+ submit_btn = gr.Button("Submit")
234
+ reset_btn = gr.Button("Reset Results")
235
+
236
+ # Add invisible text input components to match the predict function signature
237
+ text1 = gr.Textbox(visible=False)
238
+ text2 = gr.Textbox(visible=False)
239
+
240
+ # Connect the submit button to the predict function
241
+ submit_btn.click(
242
+ fn=predict,
243
+ inputs=[
244
+ text1, conc1, flow_rate1, voltage1, solvent1,
245
+ text2, conc2, flow_rate2, voltage2, solvent2
246
+ ],
247
+ outputs=[prior_experiments, results_df, perf_plot]
248
+ )
249
+
250
+ # Connect the reset button to the reset_results function
251
+ reset_btn.click(
252
+ fn=reset_results,
253
+ inputs=[],
254
+ outputs=[prior_experiments, results_df, perf_plot]
255
+ )
256
+
257
  demo.launch()