Saeed commited on
Commit
cf2ff3e
·
verified ·
1 Parent(s): ef25dd2

prompt and other parts were optimized

Browse files
Files changed (1) hide show
  1. app.py +55 -30
app.py CHANGED
@@ -4,7 +4,6 @@ import pandas as pd
4
  import joblib
5
  import optuna
6
  import numpy as np
7
- import openai
8
  from catboost import CatBoostClassifier
9
 
10
 
@@ -185,6 +184,7 @@ BIOMATERIAL_OPTIONS = [
185
  ]
186
 
187
  CELL_LINE_OPTIONS = [
 
188
  "chondrocyteyte",
189
  "HepG2",
190
  "bMSCs",
@@ -472,23 +472,34 @@ st.subheader("Cell Line & Density (10^6 cells/ml)")
472
  col1, col2, col3, col4 = st.columns([2,1,1,1])
473
  cell_line = col1.selectbox("Cell Line", CELL_LINE_OPTIONS)
474
 
475
- dr = st.session_state.density_range
476
- dmin = col2.number_input(
477
- "Min Density", min_value=0.0, max_value=dr['max'],
478
- value=dr['min'], step=dr['step'], key="cd_min"
479
- )
480
- dmax = col3.number_input(
481
- "Max Density", min_value=dr['step'], max_value=1000.0,
482
- value=max(dr['max'], dr['step']), step=dr['step'], key="cd_max"
483
- )
484
- dr.update(min=dmin, max=dmax)
485
-
486
- dr['step'] = col4.number_input(
487
- "Step", min_value=0.0,
488
- max_value=(dmax - dmin) if dmax > dmin else 0.1,
489
- value=dr['step'], step=0.1, key="cd_step"
490
- )
491
-
 
 
 
 
 
 
 
 
 
 
 
492
  st.markdown("---")
493
 
494
  st.subheader("Printing Parameters (enter range)")
@@ -559,10 +570,23 @@ if st.button("🛠️ Optimize WSSQ"):
559
  exp_p = float(np.dot(p_proba, model_print.classes_.astype(float)))
560
  exp_c = float(np.dot(c_proba, model_cell .classes_.astype(float)))
561
 
 
562
  return scaffold_quality_combined(exp_p, exp_c)
563
 
564
- study = optuna.create_study(direction="maximize")
565
- study.optimize(objective, n_trials=50)
 
 
 
 
 
 
 
 
 
 
 
 
566
  best = study.best_trial
567
 
568
  st.success(f"🏆 Best WSSQ: **{best.value:.3f}**")
@@ -576,27 +600,28 @@ if st.button("🛠️ Optimize WSSQ"):
576
  with st.spinner("Generating rigorous fabrication procedure…"):
577
 
578
  formatted_params = "\n".join([
579
- f"- {k.replace('bio__', 'Biomaterial: ').replace('pp__', 'Print Setting: ')}: {v:.2f}"
580
  for k, v in best.params.items()
581
  ])
582
 
583
  prompt = (
584
  f"Please act as a senior tissue engineer with 15+ years of hands-on experience in 3D bioprinting for regenerative medicine. "
585
- f"Write a **highly practical, bench-ready laboratory fabrication protocol** for 3D bioprinting a cell-laden scaffold. "
586
- f"The protocol must be written so that a trained experimentalist can follow it directly in a standard tissue engineering lab (biosafety cabinet, extrusion bioprinter, 37 °C/5 % CO₂ incubator, centrifuge, etc.) with zero ambiguity.\n\n"
587
-
588
  f"**Use exactly these inputs to tailor every step:**\n"
589
  f"Target Cell Line: {cell_line}\n"
590
  f"Parameters:\n{formatted_params}\n\n"
591
-
592
  f"**Critical requirements for the protocol (you MUST follow all of them):**\n"
593
- f"• Every quantity must be given in measurable lab units (e.g., 2.5 mL, 1.2 % w/v, 10 mg/mL, 37 °C, 5 min, 150 rpm).\n"
594
- f"• Include exact timings, temperatures, and workflow order to protect cell viability (target >85 % post-print) and maintain scaffold fidelity.\n"
 
 
595
  f"• Anticipate and explicitly address common bioprinting pitfalls relevant to the given parameters (nozzle clogging, shear-induced cell death, premature gelation, filament fusion, air bubbles, etc.) and give precise mitigation steps.\n"
596
- f"• Emphasize aseptic technique, sterility, and biosafety at every stage.\n"
597
  f"• Use only reagents and equipment that are standard in tissue engineering labs; if a specific brand/model is implied by the parameters, note a common equivalent.\n"
598
- f"• Include simple quality-control checkpoints (visual inspection, live/dead staining timing, etc.).\n\n"
599
-
600
  f"Your response must be structured **exactly** with the following sections (no extra sections, no introductory text, no summary, no conclusions):\n"
601
  f"1. Required Materials & Equipment\n"
602
  f"2. Sterilization & Safety Precautions\n"
 
4
  import joblib
5
  import optuna
6
  import numpy as np
 
7
  from catboost import CatBoostClassifier
8
 
9
 
 
184
  ]
185
 
186
  CELL_LINE_OPTIONS = [
187
+ "NoCellCultured",
188
  "chondrocyteyte",
189
  "HepG2",
190
  "bMSCs",
 
472
  col1, col2, col3, col4 = st.columns([2,1,1,1])
473
  cell_line = col1.selectbox("Cell Line", CELL_LINE_OPTIONS)
474
 
475
+ # ── Special handling for NoCellCultured (acellular 3D printing) ──
476
+ if cell_line == "NoCellCultured":
477
+ st.info("🧪 **Acellular 3D printing mode** – No cells will be included. Cell density is forced to 0.")
478
+ # Force density to zero
479
+ st.session_state.density_range.update({'min': 0.0, 'max': 0.0, 'step': 0.0})
480
+
481
+ # Show disabled-looking fields (read-only)
482
+ col2.number_input("Min Density", value=0.0, disabled=True, key="cd_min")
483
+ col3.number_input("Max Density", value=0.0, disabled=True, key="cd_max")
484
+ col4.number_input("Step", value=0.0, disabled=True, key="cd_step")
485
+ else:
486
+ # Normal cell-laden mode
487
+ dr = st.session_state.density_range
488
+ dmin = col2.number_input(
489
+ "Min Density", min_value=0.0, max_value=dr['max'],
490
+ value=dr['min'], step=dr['step'], key="cd_min"
491
+ )
492
+ dmax = col3.number_input(
493
+ "Max Density", min_value=dr['step'], max_value=1000.0,
494
+ value=max(dr['max'], dr['step']), step=dr['step'], key="cd_max"
495
+ )
496
+ dstep = col4.number_input(
497
+ "Step", min_value=0.0,
498
+ max_value=(dmax - dmin) if dmax > dmin else 0.1,
499
+ value=dr['step'], step=0.1, key="cd_step"
500
+ )
501
+ st.session_state.density_range.update({'min': dmin, 'max': dmax, 'step': dstep})
502
+
503
  st.markdown("---")
504
 
505
  st.subheader("Printing Parameters (enter range)")
 
570
  exp_p = float(np.dot(p_proba, model_print.classes_.astype(float)))
571
  exp_c = float(np.dot(c_proba, model_cell .classes_.astype(float)))
572
 
573
+ np.random.seed(42)
574
  return scaffold_quality_combined(exp_p, exp_c)
575
 
576
+ sampler = optuna.samplers.TPESampler(
577
+ seed=42,
578
+ n_startup_trials=30,
579
+ multivariate=True,
580
+ group=True,
581
+ consider_prior=True
582
+ )
583
+
584
+ study = optuna.create_study(
585
+ direction="maximize",
586
+ sampler=sampler,
587
+ pruner=optuna.pruners.MedianPruner()
588
+ )
589
+ study.optimize(objective, n_trials=300)
590
  best = study.best_trial
591
 
592
  st.success(f"🏆 Best WSSQ: **{best.value:.3f}**")
 
600
  with st.spinner("Generating rigorous fabrication procedure…"):
601
 
602
  formatted_params = "\n".join([
603
+ f"- {k.replace('bio__', 'Biomaterial: ').replace('pp__', 'Print Setting: ')}: {v:.2f}"
604
  for k, v in best.params.items()
605
  ])
606
 
607
  prompt = (
608
  f"Please act as a senior tissue engineer with 15+ years of hands-on experience in 3D bioprinting for regenerative medicine. "
609
+ f"Write a **highly practical, bench-ready laboratory fabrication protocol** for fabricating a scaffold. "
610
+ f"Assume the reader is an experienced experimentalist who routinely works in a tissue engineering lab.\n\n"
611
+
612
  f"**Use exactly these inputs to tailor every step:**\n"
613
  f"Target Cell Line: {cell_line}\n"
614
  f"Parameters:\n{formatted_params}\n\n"
615
+
616
  f"**Critical requirements for the protocol (you MUST follow all of them):**\n"
617
+ f"• If Target Cell Line is 'NoCellCultured', this is **acellular 3D printing** (not bioprinting). Remove all references to cells, cell viability, cell density, and cell culturing. The final scaffold is cell-free. Change section 6 title to 'Post-Printing Incubation & Storage Instructions' and adapt its content accordingly.\n"
618
+ f"• If any suggested parameter is physically unrealistic (e.g. nozzle diameter 9 µm or syringe temp 2°C) or the nozzle diameter is very small relative to the cell diameter of the target cell line (when cells are used), adjust it slightly in the protocol and explicitly note the adjustment with justification.\n"
619
+ f"• Every quantity must be given in precise, measurable lab units (e.g., 2.5 mL, 1.2 % w/v, 10 mg/mL, 37 °C, 5 min, 150 rpm).\n"
620
+ f"• Include exact timings, temperatures, and workflow order to protect structural fidelity (and cell viability >85 % post-print when cells are used).\n"
621
  f"• Anticipate and explicitly address common bioprinting pitfalls relevant to the given parameters (nozzle clogging, shear-induced cell death, premature gelation, filament fusion, air bubbles, etc.) and give precise mitigation steps.\n"
 
622
  f"• Use only reagents and equipment that are standard in tissue engineering labs; if a specific brand/model is implied by the parameters, note a common equivalent.\n"
623
+ f"• Include simple quality-control checkpoints (visual inspection, live/dead staining timing when cells are used, etc.).\n\n"
624
+
625
  f"Your response must be structured **exactly** with the following sections (no extra sections, no introductory text, no summary, no conclusions):\n"
626
  f"1. Required Materials & Equipment\n"
627
  f"2. Sterilization & Safety Precautions\n"