Spaces:
Running
Running
Commit
·
f3034bd
1
Parent(s):
51b03b4
user specific data
Browse files
app.py
CHANGED
@@ -7,9 +7,7 @@ import plotly.express as px
|
|
7 |
|
8 |
import pandas as pd
|
9 |
|
10 |
-
#
|
11 |
-
results_storage = pd.DataFrame(columns=['Concentration (%w/v)', 'Flow Rate (mL/h)', 'Voltage (kV)', 'Solvent', 'Size (um)', 'Feasible?'])
|
12 |
-
|
13 |
# define a Dataframe styler to highlight the Feasible? column to be green and red
|
14 |
def highlight_success(val):
|
15 |
color = 'lightgreen' if val == 'Success' else 'lightcoral'
|
@@ -149,8 +147,14 @@ def plot_results(exp_data_df):
|
|
149 |
|
150 |
return fig
|
151 |
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
solvent_value1 = 0 if solvent1 == 'DMAc' else 1
|
155 |
solvent_value2 = 0 if solvent2 == 'DMAc' else 1
|
156 |
|
@@ -181,12 +185,12 @@ def predict(text1, conc1, flow_rate1, voltage1, solvent1, text2, conc2, flow_rat
|
|
181 |
results_storage = pd.concat([results_storage, results_df], ignore_index=True)
|
182 |
results_display = results_storage.style.map(highlight_success, subset=['Feasible?']).format(precision=3)
|
183 |
|
184 |
-
return (gr_exp_record_df, gr.DataFrame(value=results_display, label="Your Results"), plot_results(results_storage))
|
185 |
|
186 |
-
|
187 |
-
|
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"),
|
@@ -210,6 +214,10 @@ 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")
|
@@ -241,17 +249,18 @@ with gr.Blocks() as demo:
|
|
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()
|
|
|
7 |
|
8 |
import pandas as pd
|
9 |
|
10 |
+
# Remove the global variable and instead use gr.State
|
|
|
|
|
11 |
# define a Dataframe styler to highlight the Feasible? column to be green and red
|
12 |
def highlight_success(val):
|
13 |
color = 'lightgreen' if val == 'Success' else 'lightcoral'
|
|
|
147 |
|
148 |
return fig
|
149 |
|
150 |
+
# Update predict function to use state
|
151 |
+
def predict(state, text1, conc1, flow_rate1, voltage1, solvent1, text2, conc2, flow_rate2, voltage2, solvent2):
|
152 |
+
# Get current results storage from state or initialize if None
|
153 |
+
if state is None:
|
154 |
+
results_storage = pd.DataFrame(columns=['Concentration (%w/v)', 'Flow Rate (mL/h)', 'Voltage (kV)', 'Solvent', 'Size (um)', 'Feasible?'])
|
155 |
+
else:
|
156 |
+
results_storage = state.copy()
|
157 |
+
|
158 |
solvent_value1 = 0 if solvent1 == 'DMAc' else 1
|
159 |
solvent_value2 = 0 if solvent2 == 'DMAc' else 1
|
160 |
|
|
|
185 |
results_storage = pd.concat([results_storage, results_df], ignore_index=True)
|
186 |
results_display = results_storage.style.map(highlight_success, subset=['Feasible?']).format(precision=3)
|
187 |
|
188 |
+
return (results_storage, gr_exp_record_df, gr.DataFrame(value=results_display, label="Your Results"), plot_results(results_storage))
|
189 |
|
190 |
+
# Update reset_results to use state
|
191 |
+
def reset_results(state):
|
192 |
results_storage = pd.DataFrame(columns=['Concentration (%w/v)', 'Flow Rate (mL/h)', 'Voltage (kV)', 'Solvent', 'Size (um)', 'Feasible?'])
|
193 |
+
return (results_storage, 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))
|
194 |
|
195 |
inputs = [
|
196 |
gr.Markdown("### Experiment 1"),
|
|
|
214 |
|
215 |
gr.Markdown("## Human vs CCBO Campaign - Simulated Electrospray")
|
216 |
gr.Markdown(description)
|
217 |
+
|
218 |
+
# Add state component to store user-specific results
|
219 |
+
results_state = gr.State()
|
220 |
+
|
221 |
with gr.Row():
|
222 |
with gr.Column():
|
223 |
gr.Markdown("### Experiment 1")
|
|
|
249 |
submit_btn.click(
|
250 |
fn=predict,
|
251 |
inputs=[
|
252 |
+
results_state,
|
253 |
text1, conc1, flow_rate1, voltage1, solvent1,
|
254 |
text2, conc2, flow_rate2, voltage2, solvent2
|
255 |
],
|
256 |
+
outputs=[results_state, prior_experiments, results_df, perf_plot]
|
257 |
)
|
258 |
|
259 |
# Connect the reset button to the reset_results function
|
260 |
reset_btn.click(
|
261 |
fn=reset_results,
|
262 |
+
inputs=[results_state],
|
263 |
+
outputs=[results_state, prior_experiments, results_df, perf_plot]
|
264 |
)
|
265 |
|
266 |
demo.launch()
|