snajmark commited on
Commit
9d60b86
·
1 Parent(s): d34ac44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -107,17 +107,18 @@ def predict(x, request: gr.Request):
107
  return (round(y_hardness*(maximum_hardness-minimum_hardness)+minimum_hardness, 2), 12,
108
  round(y_ys*(maximum_ys-minimum_ys)+minimum_ys, 2), 12)
109
 
110
- def fit_outputs(X, reduction_target):
 
111
  reduction_target_df = pd.DataFrame({'Reduction_%':[reduction_target]})
112
  reduction_target_df = scale_numerical(reduction_target_df, ['Reduction_%'], scaler=minmax_scaler_targets, fit=False)
113
  predictions = model.predict(X)[0]
114
  error = np.sqrt(np.square(predictions[0]-reduction_target))
115
  return error
116
 
117
- def predict_inverse(reduction_target, request: gr.Request):
118
 
119
  def fit_outputs(x):
120
- return fit_outputs_constraints(x, reduction_target, request)
121
  opt = GPyOpt.methods.BayesianOptimization(f = fit_outputs, # function to optimize
122
  domain = domain, # box-constraints of the problem
123
  constraints = constraints,
@@ -143,7 +144,7 @@ def predict_inverse(reduction_target, request: gr.Request):
143
  return optimized_x.transpose()
144
 
145
 
146
- example_inputs = [20]
147
 
148
  css_styling = """#submit {background: #1eccd8}
149
  #submit:hover {background: #a2f1f6}
@@ -180,8 +181,8 @@ with gr.Blocks(css=css_styling, title=page_title, theme=osium_theme) as demo:
180
  prediction_button = gr.Button("Predict", elem_id="submit")
181
  with gr.Row():
182
  with gr.Column():
183
- gr.Markdown("### The target performance of your alloy")
184
- reduction_target = gr.Text(label="Enter your maximal acceptable antimicrobial activity reduction you would like for your coating")
185
 
186
  with gr.Column():
187
  with gr.Row():
@@ -196,7 +197,7 @@ with gr.Blocks(css=css_styling, title=page_title, theme=osium_theme) as demo:
196
 
197
  prediction_button.click(
198
  fn=predict_inverse,
199
- inputs=[reduction_target],
200
  outputs=[optimal_conditions],
201
  show_progress=True,
202
  )
@@ -204,7 +205,7 @@ with gr.Blocks(css=css_styling, title=page_title, theme=osium_theme) as demo:
204
  lambda x: [gr.update(value=None)] * 2,
205
  [],
206
  [
207
- reduction_target,
208
  optimal_conditions,
209
  ],
210
  )
 
107
  return (round(y_hardness*(maximum_hardness-minimum_hardness)+minimum_hardness, 2), 12,
108
  round(y_ys*(maximum_ys-minimum_ys)+minimum_ys, 2), 12)
109
 
110
+ def fit_outputs(X, antimicrobial_activity_target):
111
+ reduction_target = 100 - antimicrobial_activity_target
112
  reduction_target_df = pd.DataFrame({'Reduction_%':[reduction_target]})
113
  reduction_target_df = scale_numerical(reduction_target_df, ['Reduction_%'], scaler=minmax_scaler_targets, fit=False)
114
  predictions = model.predict(X)[0]
115
  error = np.sqrt(np.square(predictions[0]-reduction_target))
116
  return error
117
 
118
+ def predict_inverse(antimicrobial_activity_target, request: gr.Request):
119
 
120
  def fit_outputs(x):
121
+ return fit_outputs_constraints(x, antimicrobial_activity_target, request)
122
  opt = GPyOpt.methods.BayesianOptimization(f = fit_outputs, # function to optimize
123
  domain = domain, # box-constraints of the problem
124
  constraints = constraints,
 
144
  return optimized_x.transpose()
145
 
146
 
147
+ example_inputs = [80]
148
 
149
  css_styling = """#submit {background: #1eccd8}
150
  #submit:hover {background: #a2f1f6}
 
181
  prediction_button = gr.Button("Predict", elem_id="submit")
182
  with gr.Row():
183
  with gr.Column():
184
+ gr.Markdown("### The target antimicrobial activity of your textile coating")
185
+ antimicrobial_activity_target = gr.Text(label="Enter the minimum acceptable antimicrobial activity for your textile coating")
186
 
187
  with gr.Column():
188
  with gr.Row():
 
197
 
198
  prediction_button.click(
199
  fn=predict_inverse,
200
+ inputs=[antimicrobial_activity_target],
201
  outputs=[optimal_conditions],
202
  show_progress=True,
203
  )
 
205
  lambda x: [gr.update(value=None)] * 2,
206
  [],
207
  [
208
+ antimicrobial_activity_target,
209
  optimal_conditions,
210
  ],
211
  )