AdrianM0 commited on
Commit
fbe0ff9
·
verified ·
1 Parent(s): fe32912

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +4 -27
app.py CHANGED
@@ -629,7 +629,7 @@ def load_model_and_tokenizers():
629
 
630
 
631
  # --- Inference Function for Gradio ---
632
- def predict_iupac(smiles_string, beam_width_str, n_best_str, length_penalty_str):
633
  """
634
  Performs SMILES to IUPAC translation using the loaded model and beam search.
635
  Takes string inputs from Gradio sliders/inputs and converts them.
@@ -660,26 +660,16 @@ def predict_iupac(smiles_string, beam_width_str, n_best_str, length_penalty_str)
660
  try:
661
  beam_width = int(beam_width_str)
662
  n_best = int(n_best_str)
663
- length_penalty = float(length_penalty_str)
664
  if beam_width < 1 or n_best < 1 or n_best > beam_width:
665
  raise ValueError(
666
  "Beam width and n_best must be >= 1, and n_best <= beam width."
667
  )
668
- if length_penalty < 0:
669
- logging.warning(
670
- f"Length penalty {length_penalty} is negative, using 0.0 instead."
671
- )
672
- length_penalty = 0.0
673
  except ValueError as e:
674
  error_msg = f"Error: Invalid input parameter ({e}). Please check beam width, n_best, and length penalty values."
675
  logging.error(error_msg)
676
  # Cannot determine n_best if its input was invalid, default to 1 error line
677
  return f"1. {error_msg}"
678
 
679
- logging.info(
680
- f"Translating SMILES: '{smiles_input}' (Beam={beam_width}, N={n_best}, Penalty={length_penalty:.2f})"
681
- )
682
-
683
  try:
684
  # --- Call the core translation logic ---
685
  # Retrieve necessary IDs from the loaded config
@@ -700,7 +690,7 @@ def predict_iupac(smiles_string, beam_width_str, n_best_str, length_penalty_str)
700
  pad_idx=pad_idx,
701
  beam_width=beam_width,
702
  n_best=n_best,
703
- length_penalty=length_penalty,
704
  )
705
  logging.info(f"Predictions returned: {predicted_names}")
706
 
@@ -801,14 +791,7 @@ n_best_input = gr.Slider(
801
  label="Number of Results (n_best)",
802
  info="How many top sequences to return (must be <= Beam Width).",
803
  )
804
- length_penalty_input = gr.Slider(
805
- minimum=0.0,
806
- maximum=2.0,
807
- value=0.6,
808
- step=0.1,
809
- label="Length Penalty (alpha)",
810
- info="Controls preference for sequence length. >1 favors longer, <1 favors shorter, 0 no penalty.",
811
- )
812
  output_text = gr.Textbox(
813
  label="Predicted IUPAC Name(s)", lines=5, show_copy_button=True
814
  )
@@ -820,7 +803,6 @@ iface = gr.Interface(
820
  smiles_input,
821
  beam_width_input,
822
  n_best_input,
823
- length_penalty_input,
824
  ],
825
  outputs=output_text, # Output component
826
  title=title,
@@ -839,9 +821,4 @@ iface = gr.Interface(
839
 
840
  # --- Launch the App ---
841
  if __name__ == "__main__":
842
- # Launch the Gradio interface
843
- # share=True generates a public link (useful for testing outside HF Spaces, but temporary)
844
- # Set share=False or remove for deployment on Spaces.
845
- # Use server_name="0.0.0.0" to make it accessible on the network if running locally
846
- # Use auth=("username", "password") for basic authentication
847
- iface.launch() # share=True is deprecated, use launch()
 
629
 
630
 
631
  # --- Inference Function for Gradio ---
632
+ def predict_iupac(smiles_string, beam_width_str, n_best_str):
633
  """
634
  Performs SMILES to IUPAC translation using the loaded model and beam search.
635
  Takes string inputs from Gradio sliders/inputs and converts them.
 
660
  try:
661
  beam_width = int(beam_width_str)
662
  n_best = int(n_best_str)
 
663
  if beam_width < 1 or n_best < 1 or n_best > beam_width:
664
  raise ValueError(
665
  "Beam width and n_best must be >= 1, and n_best <= beam width."
666
  )
 
 
 
 
 
667
  except ValueError as e:
668
  error_msg = f"Error: Invalid input parameter ({e}). Please check beam width, n_best, and length penalty values."
669
  logging.error(error_msg)
670
  # Cannot determine n_best if its input was invalid, default to 1 error line
671
  return f"1. {error_msg}"
672
 
 
 
 
 
673
  try:
674
  # --- Call the core translation logic ---
675
  # Retrieve necessary IDs from the loaded config
 
690
  pad_idx=pad_idx,
691
  beam_width=beam_width,
692
  n_best=n_best,
693
+ length_penalty=0.0,
694
  )
695
  logging.info(f"Predictions returned: {predicted_names}")
696
 
 
791
  label="Number of Results (n_best)",
792
  info="How many top sequences to return (must be <= Beam Width).",
793
  )
794
+
 
 
 
 
 
 
 
795
  output_text = gr.Textbox(
796
  label="Predicted IUPAC Name(s)", lines=5, show_copy_button=True
797
  )
 
803
  smiles_input,
804
  beam_width_input,
805
  n_best_input,
 
806
  ],
807
  outputs=output_text, # Output component
808
  title=title,
 
821
 
822
  # --- Launch the App ---
823
  if __name__ == "__main__":
824
+ iface.launch()