C2MV commited on
Commit
3086146
·
verified ·
1 Parent(s): cfa4496

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -479,9 +479,6 @@ class BioprocessModel:
479
  solP = np.maximum(sol[:,2], 0)
480
  return solX, solS, solP, time_f
481
 
482
- # plot_results and plot_combined_results remain largely the same as previous version,
483
- # ensure they handle None from y_pred_biomass_fit gracefully.
484
- # (Code for plot_results and plot_combined_results is omitted here for brevity but assumed to be from the previous corrected version)
485
  def plot_results(self, time, biomass, substrate, product,
486
  y_pred_biomass_fit, y_pred_substrate_fit, y_pred_product_fit,
487
  biomass_std=None, substrate_std=None, product_std=None,
@@ -567,7 +564,10 @@ class BioprocessModel:
567
  if show_legend: ax.legend(loc=legend_position)
568
  if show_params and p_dict and any(np.isfinite(v) for v in p_dict.values()):
569
  p_txt='\n'.join([f"{k}={v:.3g}" if np.isfinite(v) else f"{k}=N/A" for k,v in p_dict.items()])
570
- txt=f"{p_txt}\nR²={r2_val:.3f if np.isfinite(r2_val) else 'N/A'}\nRMSE={rmse_val:.3f if np.isfinite(rmse_val) else 'N/A'}"
 
 
 
571
  if params_position=='outside right':
572
  fig.subplots_adjust(right=0.70)
573
  ax.annotate(txt,xy=(1.05,0.5),xycoords='axes fraction',xytext=(10,0),textcoords='offset points',va='center',ha='left',bbox={'boxstyle':'round,pad=0.3','facecolor':'wheat','alpha':0.7}, fontsize=8)
@@ -673,7 +673,10 @@ class BioprocessModel:
673
  (axis_labels['product_label'], self.params.get('product',{}), self.r2.get('product',np.nan), self.rmse.get('product',np.nan))]:
674
  if p_dict and any(np.isfinite(v) for v in p_dict.values()):
675
  p_list = [f" {k}={v:.3g}" if np.isfinite(v) else f" {k}=N/A" for k,v in p_dict.items()]
676
- all_param_text.append(f"{cat_label}:\n" + "\n".join(p_list) + f"\n R²={r2_val:.3f if np.isfinite(r2_val) else 'N/A'}\n RMSE={rmse_val:.3f if np.isfinite(rmse_val) else 'N/A'}")
 
 
 
677
  total_text = "\n\n".join(all_param_text)
678
  if total_text:
679
  if params_position=='outside right':
@@ -887,10 +890,6 @@ def process_all_data(file, legend_position, params_position, model_types_selecte
887
 
888
  return figures_with_names, comparison_df_sorted, final_message, all_parameters_collected
889
 
890
- # ... (MODEL_CHOICES, create_zip_of_images, create_interface, and __main__ block remain the same as the previous corrected version)
891
- # Ensure create_interface uses the corrected gr.Dataframe without 'height'
892
- # The rest of the UI and helper functions (create_zip_of_images, export functions) are assumed to be correct from the prior version.
893
-
894
  MODEL_CHOICES = [("Logistic (3-parám)","logistic"),("Gompertz (3-parám)","gompertz"),("Moser (3-parám)","moser"),("Baranyi (4-parám)","baranyi")]
895
 
896
  def create_zip_of_images(figures_with_names_list, base_zip_filename="plots"):
 
479
  solP = np.maximum(sol[:,2], 0)
480
  return solX, solS, solP, time_f
481
 
 
 
 
482
  def plot_results(self, time, biomass, substrate, product,
483
  y_pred_biomass_fit, y_pred_substrate_fit, y_pred_product_fit,
484
  biomass_std=None, substrate_std=None, product_std=None,
 
564
  if show_legend: ax.legend(loc=legend_position)
565
  if show_params and p_dict and any(np.isfinite(v) for v in p_dict.values()):
566
  p_txt='\n'.join([f"{k}={v:.3g}" if np.isfinite(v) else f"{k}=N/A" for k,v in p_dict.items()])
567
+ # FIXED: Compute formatted strings separately
568
+ r2_str = f"{r2_val:.3f}" if np.isfinite(r2_val) else 'N/A'
569
+ rmse_str = f"{rmse_val:.3f}" if np.isfinite(rmse_val) else 'N/A'
570
+ txt = f"{p_txt}\nR²={r2_str}\nRMSE={rmse_str}"
571
  if params_position=='outside right':
572
  fig.subplots_adjust(right=0.70)
573
  ax.annotate(txt,xy=(1.05,0.5),xycoords='axes fraction',xytext=(10,0),textcoords='offset points',va='center',ha='left',bbox={'boxstyle':'round,pad=0.3','facecolor':'wheat','alpha':0.7}, fontsize=8)
 
673
  (axis_labels['product_label'], self.params.get('product',{}), self.r2.get('product',np.nan), self.rmse.get('product',np.nan))]:
674
  if p_dict and any(np.isfinite(v) for v in p_dict.values()):
675
  p_list = [f" {k}={v:.3g}" if np.isfinite(v) else f" {k}=N/A" for k,v in p_dict.items()]
676
+ # FIXED: Compute formatted strings separately
677
+ r2_str = f"{r2_val:.3f}" if np.isfinite(r2_val) else 'N/A'
678
+ rmse_str = f"{rmse_val:.3f}" if np.isfinite(rmse_val) else 'N/A'
679
+ all_param_text.append(f"{cat_label}:\n" + "\n".join(p_list) + f"\n R²={r2_str}\n RMSE={rmse_str}")
680
  total_text = "\n\n".join(all_param_text)
681
  if total_text:
682
  if params_position=='outside right':
 
890
 
891
  return figures_with_names, comparison_df_sorted, final_message, all_parameters_collected
892
 
 
 
 
 
893
  MODEL_CHOICES = [("Logistic (3-parám)","logistic"),("Gompertz (3-parám)","gompertz"),("Moser (3-parám)","moser"),("Baranyi (4-parám)","baranyi")]
894
 
895
  def create_zip_of_images(figures_with_names_list, base_zip_filename="plots"):