bcadkins01 commited on
Commit
0db5108
·
verified ·
1 Parent(s): a095a44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -10,8 +10,6 @@ import io
10
  from PIL import Image
11
  import cairosvg
12
  import pandas as pd
13
- import streamlit.components.v1 as components
14
- import json # For safely encoding text in JavaScript
15
 
16
  # Page Configuration
17
  st.set_page_config(
@@ -27,7 +25,7 @@ def load_models():
27
  Caches the models to avoid reloading on every run.
28
  """
29
  # Load your molecule generation model
30
- model_name = "bcadkins01/beta_lactam_generator" # Replace with your actual model path
31
  access_token = os.getenv("HUGGING_FACE_TOKEN")
32
  if access_token is None:
33
  st.error("Access token not found. Please set the HUGGING_FACE_TOKEN environment variable.")
@@ -53,10 +51,10 @@ creativity = st.sidebar.slider(
53
  max_value=2.4,
54
  value=1.0,
55
  step=0.2,
56
- help="Higher values lead to more diverse outputs."
57
  )
58
 
59
- # **Number of Molecules to Generate**
60
  num_molecules = st.sidebar.number_input(
61
  'Number of Molecules to Generate:',
62
  min_value=1,
@@ -91,7 +89,6 @@ def generate_molecule_image(input_string, use_safe=False):
91
  st.error(f"Error generating molecule image: {e}")
92
  return None
93
 
94
-
95
  # Generate Molecules Button
96
  if st.button('Generate Molecules'):
97
  st.info("Generating molecules... Please wait.")
@@ -110,7 +107,7 @@ if st.button('Generate Molecules'):
110
  do_sample=True,
111
  top_k=50,
112
  num_return_sequences=num_molecules,
113
- num_beams=max(num_molecules, 5) # Ensure num_beams >= num_return_sequences
114
  )
115
 
116
  # Decode generated molecule SMILES
@@ -200,13 +197,11 @@ if st.button('Generate Molecules'):
200
  # Display SMILES string
201
  st.write("**SMILES:**")
202
  st.text(smiles)
203
- st_copy_button(smiles, key=f'copy_smiles_{mol_name}')
204
 
205
  # Display SAFE encoding if available
206
  if safe_string:
207
  st.write("**SAFE Encoding:**")
208
  st.text(safe_string)
209
- st_copy_button(safe_string, key=f'copy_safe_{mol_name}')
210
  # Optionally display SAFE visualization
211
  safe_img = generate_molecule_image(safe_string, use_safe=True)
212
  if safe_img is not None:
@@ -218,3 +213,4 @@ if st.button('Generate Molecules'):
218
  st.write(admet_data)
219
  else:
220
  st.write("Click the 'Generate Molecules' button to generate beta-lactam molecules.")
 
 
10
  from PIL import Image
11
  import cairosvg
12
  import pandas as pd
 
 
13
 
14
  # Page Configuration
15
  st.set_page_config(
 
25
  Caches the models to avoid reloading on every run.
26
  """
27
  # Load your molecule generation model
28
+ model_name = "bcadkins01/beta_lactam_generator"
29
  access_token = os.getenv("HUGGING_FACE_TOKEN")
30
  if access_token is None:
31
  st.error("Access token not found. Please set the HUGGING_FACE_TOKEN environment variable.")
 
51
  max_value=2.4,
52
  value=1.0,
53
  step=0.2,
54
+ help="Higher values lead to more diverse (or wild) outputs."
55
  )
56
 
57
+ # Number of Molecules to Generate
58
  num_molecules = st.sidebar.number_input(
59
  'Number of Molecules to Generate:',
60
  min_value=1,
 
89
  st.error(f"Error generating molecule image: {e}")
90
  return None
91
 
 
92
  # Generate Molecules Button
93
  if st.button('Generate Molecules'):
94
  st.info("Generating molecules... Please wait.")
 
107
  do_sample=True,
108
  top_k=50,
109
  num_return_sequences=num_molecules,
110
+ num_beams=1 # set to 1 when using sampling
111
  )
112
 
113
  # Decode generated molecule SMILES
 
197
  # Display SMILES string
198
  st.write("**SMILES:**")
199
  st.text(smiles)
 
200
 
201
  # Display SAFE encoding if available
202
  if safe_string:
203
  st.write("**SAFE Encoding:**")
204
  st.text(safe_string)
 
205
  # Optionally display SAFE visualization
206
  safe_img = generate_molecule_image(safe_string, use_safe=True)
207
  if safe_img is not None:
 
213
  st.write(admet_data)
214
  else:
215
  st.write("Click the 'Generate Molecules' button to generate beta-lactam molecules.")
216
+