tyang4 commited on
Commit
867a761
·
verified ·
1 Parent(s): 0e4dd50

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -1
src/streamlit_app.py CHANGED
@@ -499,6 +499,20 @@ Plain text only — no code fences. Markdown link syntax (`[text](url)`) is allo
499
  # return rsp.choices[0].message.content.strip()
500
 
501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
 
503
 
504
 
@@ -1029,7 +1043,19 @@ if st.session_state.do_visualize:
1029
  if mol_img is not None:
1030
  st.image(mol_img, caption=f"{smiles_col}: {sel}")
1031
  else:
1032
- st.warning("Could not parse structure for visualization.")
 
 
 
 
 
 
 
 
 
 
 
 
1033
 
1034
  # 2. 官能团/片段/名称分布柱状图
1035
  count_col = None
 
499
  # return rsp.choices[0].message.content.strip()
500
 
501
 
502
+ def gpt_fix_smiles(bad_smiles, client):
503
+ prompt = f"""
504
+ The following is an invalid or broken SMILES or SMARTS string: '{bad_smiles}'
505
+ Please correct it if possible. Only return a valid SMILES/SMARTS string, or say 'INVALID' if impossible.
506
+ """
507
+ rsp = client.chat.completions.create(
508
+ model="gpt-4o",
509
+ messages=[{"role": "user", "content": prompt}],
510
+ temperature=0.0,
511
+ max_tokens=30,
512
+ n=1,
513
+ )
514
+ answer = rsp.choices[0].message.content.strip()
515
+ return answer if answer.upper() != 'INVALID' else None
516
 
517
 
518
 
 
1043
  if mol_img is not None:
1044
  st.image(mol_img, caption=f"{smiles_col}: {sel}")
1045
  else:
1046
+ st.warning("Could not parse structure. Trying to auto-fix…")
1047
+ # ⬇️ 自动尝试用 GPT 修复
1048
+ fixed = gpt_fix_smiles(sel, openai_client)
1049
+ if fixed and fixed != sel:
1050
+ st.info(f"🔄 Auto-corrected: {fixed}")
1051
+ fixed_img = get_mol_img(fixed)
1052
+ if fixed_img is not None:
1053
+ st.image(fixed_img, caption=f"Auto-fixed: {fixed}")
1054
+ else:
1055
+ st.warning("Still could not parse after fixing.")
1056
+ else:
1057
+ st.warning("Unable to auto-correct structure.")
1058
+
1059
 
1060
  # 2. 官能团/片段/名称分布柱状图
1061
  count_col = None