wg25r commited on
Commit
ac549f4
·
1 Parent(s): a2d5af5

better GUI with gpt

Browse files
Files changed (1) hide show
  1. app.py +32 -25
app.py CHANGED
@@ -36,40 +36,47 @@ This app generates SMILES strings from images of molecules ball-and-stick models
36
  col1, col2 = st.columns(2)
37
  gen_strategy = col1.selectbox("Select a generative strategy", ("Beam Search", "Sampling", "Greedy Search"))
38
  temp = col2.slider("Temperature", 0.0, 2.0, 1.0)
39
- uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg", "webp", "heic"])
40
 
41
- lib = st.columns(2)
42
- lib[0].markdown("Do not have an image? You can select a molecule from the library below.")
43
- from_library = lib[1].button("Select from Library")
44
- if from_library:
45
- lib_modal()
46
 
47
- col1, col2 = st.columns(2)
48
- if not "uploaded_file" in st.session_state:
 
 
49
  col1.checkbox("Contribute To Public Library", value=True, help="If checked, images will be included in the PUBLIC library, and the image will be reviewed by our team and used for model training. When checked, do not upload any sensitive or personal data.")
50
  else:
51
- col1.checkbox("Contribute To Public Library", value=False, disabled=True, help="When using the library, this option is disabled. If you want to contribute to the library, please upload an image.")
 
 
 
 
 
52
 
53
 
54
- button = col2.button("Submit")
55
  if button:
56
  if uploaded_file:
57
  start_time = time.time()
58
  image = Image.open(uploaded_file)
 
 
 
 
 
 
 
 
 
 
59
 
60
- options = ["CC(=O)OC1=CC=CC=C1C(=C)C(=O)O", "CC(=O)", "CC(=O)O", "CC(=O)C", "CC(=O)C1=CC=CC=C1"]
61
- grid = [st.columns(2) for _ in range(len(options) // 3 + 1)]
62
- cols = [col for row in grid for col in row]
63
-
64
- for i, (smiles, col) in enumerate(zip(options, cols)):
65
- cid = pcp.get_compounds(smiles, 'smiles')
66
- name = cid[0].synonyms[0]
67
- col.markdown(name)
68
- m = Chem.MolFromSmiles(smiles)
69
- img = Draw.MolToImage(m)
70
- col.image(img, use_container_width=False)
71
- pubchem_url = "https://pubchem.ncbi.nlm.nih.gov/compound/{}".format(cid[0].cid)
72
- col.markdown("[PubChem]({})".format(pubchem_url))
73
 
74
- st.markdown("---")
75
- st.markdown("Taken {} seconds".format(round(time.time() - start_time, 2)))
 
36
  col1, col2 = st.columns(2)
37
  gen_strategy = col1.selectbox("Select a generative strategy", ("Beam Search", "Sampling", "Greedy Search"))
38
  temp = col2.slider("Temperature", 0.0, 2.0, 1.0)
 
39
 
 
 
 
 
 
40
 
41
+ mode = st.radio("Select file source:", ["Upload File", "Choose from Our Demo Library"])
42
+ if mode == "Upload File":
43
+ st.session_state.pop("uploaded_file", None)
44
+ uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg", "webp", "heic"])
45
  col1.checkbox("Contribute To Public Library", value=True, help="If checked, images will be included in the PUBLIC library, and the image will be reviewed by our team and used for model training. When checked, do not upload any sensitive or personal data.")
46
  else:
47
+ uploaded_file = None
48
+ from_library = st.button("Select from Library")
49
+ if from_library:
50
+ lib_modal()
51
+ if "uploaded_file" in st.session_state:
52
+ st.markdown("You have selected: {}".format(st.session_state.uploaded_file))
53
 
54
 
55
+ button = st.button("Submit")
56
  if button:
57
  if uploaded_file:
58
  start_time = time.time()
59
  image = Image.open(uploaded_file)
60
+ elif "uploaded_file" in st.session_state:
61
+ start_time = time.time()
62
+ image = Image.open("lib/{}".format(st.session_state.uploaded_file))
63
+ else:
64
+ st.error("Please upload an image or select from the library.")
65
+ st.stop()
66
+
67
+ options = ["CC(=O)OC1=CC=CC=C1C(=C)C(=O)O", "CC(=O)", "CC(=O)O", "CC(=O)C", "CC(=O)C1=CC=CC=C1"]
68
+ grid = [st.columns(2) for _ in range(len(options) // 3 + 1)]
69
+ cols = [col for row in grid for col in row]
70
 
71
+ for i, (smiles, col) in enumerate(zip(options, cols)):
72
+ cid = pcp.get_compounds(smiles, 'smiles')
73
+ name = cid[0].synonyms[0]
74
+ col.markdown(f"### {name}")
75
+ m = Chem.MolFromSmiles(smiles)
76
+ img = Draw.MolToImage(m)
77
+ col.image(img, use_container_width=False)
78
+ pubchem_url = "https://pubchem.ncbi.nlm.nih.gov/compound/{}".format(cid[0].cid)
79
+ col.markdown("[PubChem]({})".format(pubchem_url))
 
 
 
 
80
 
81
+ st.markdown("---")
82
+ st.markdown("Taken {} seconds".format(round(time.time() - start_time, 2)))