alidenewade commited on
Commit
6076efe
·
verified ·
1 Parent(s): 65a2e03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -33,11 +33,12 @@ import warnings
33
  warnings.filterwarnings('ignore')
34
 
35
  # --- Page Configuration ---
 
36
  st.set_page_config(
37
  page_title="AI Drug Discovery Pipeline",
38
  page_icon="🔬",
39
  layout="wide",
40
- initial_sidebar_state="collapsed"
41
  )
42
 
43
  # Custom CSS for a professional, dark theme
@@ -156,8 +157,7 @@ def visualize_protein_3d(pdb_data: str, title="Protein 3D Structure"):
156
  if not pdb_data:
157
  return None, "Cannot generate 3D view: No PDB data provided."
158
  try:
159
- js_url = 'https://cdn.jsdelivr.net/npm/[email protected]/build/3Dmol.js'
160
- viewer = py3Dmol.view(width='100%', height=600, js=js_url)
161
  viewer.setBackgroundColor('#1C1C1C')
162
  viewer.addModel(pdb_data, "pdb")
163
  viewer.setStyle({'cartoon': {'color': 'spectrum', 'thickness': 0.8}})
@@ -448,15 +448,15 @@ def visualize_molecule_2d_3d(smiles: str, name: str):
448
  svg_2d = svg_2d.replace('fill:black', 'fill:white')
449
  svg_2d = svg_2d.replace('stroke:#000000', 'stroke:#FFFFFF')
450
  svg_2d = svg_2d.replace('fill:#000000', 'fill:#FFFFFF')
451
- svg_2d = svg_2d.replace('stroke:#000', 'stroke:#FFF')
452
  svg_2d = svg_2d.replace('fill:#000', 'fill="#FFF"')
453
  svg_2d = svg_2d.replace('stroke="rgb(0,0,0)"', 'stroke="rgb(255,255,255)"')
454
  svg_2d = svg_2d.replace('fill="rgb(0,0,0)"', 'fill="rgb(255,255,255)"')
455
  svg_2d = svg_2d.replace('stroke:rgb(0,0,0)', 'stroke:rgb(255,255,255)')
456
  svg_2d = svg_2d.replace('fill:rgb(0,0,0)', 'fill:rgb(255,255,255)')
457
  svg_2d = svg_2d.replace('color="black"', 'color="white"')
458
- svg_2d = svg_2d.replace('color:#000000', 'color:#FFFFFF')
459
- svg_2d = svg_2d.replace('color:#000', 'color:#FFF')
460
 
461
  # Aggressive regex-based fixes for all text elements
462
  # Remove any existing fill attributes from text elements and add white fill
@@ -487,8 +487,7 @@ def visualize_molecule_2d_3d(smiles: str, name: str):
487
  AllChem.MMFFOptimizeMolecule(mol_3d)
488
  sdf_data = Chem.MolToMolBlock(mol_3d)
489
 
490
- js_url = 'https://cdn.jsdelivr.net/npm/[email protected]/build/3Dmol.js'
491
- viewer = py3Dmol.view(width=400, height=300, js=js_url)
492
  viewer.setBackgroundColor('#1C1C1C')
493
  viewer.addModel(sdf_data, "sdf")
494
  viewer.setStyle({'stick': {}, 'sphere': {'scale': 0.25}})
@@ -520,8 +519,7 @@ def visualize_protein_ligand_interaction(pdb_data: str, pdb_id: str, ligand_resn
520
  return None, "Cannot generate interaction view: No PDB data provided."
521
 
522
  try:
523
- js_url = 'https://cdn.jsdelivr.net/npm/[email protected]/build/3Dmol.js'
524
- viewer = py3Dmol.view(width='100%', height=650, js=js_url)
525
  viewer.setBackgroundColor('#1C1C1C')
526
 
527
  # Add the protein structure
@@ -795,7 +793,8 @@ with tab1:
795
  with p1_tabs[0]:
796
  st.subheader(f"3D Structure for PDB ID: {pdb_id_input}")
797
  if res1.get('protein_view'):
798
- st.html(res1['protein_view'])
 
799
  else:
800
  st.warning("Could not display 3D structure. Check PDB ID and logs.")
801
 
@@ -879,7 +878,8 @@ with tab2:
879
  with p2_tabs[1]:
880
  st.subheader(f"Simulated Interaction for PDB {p2_pdb_id} with Ligand {p2_ligand_resn}")
881
  if res2.get('interaction_view'):
882
- st.html(res2['interaction_view'])
 
883
  else:
884
  st.warning("Could not display interaction view. Check inputs and logs.")
885
 
@@ -941,7 +941,8 @@ with tab3:
941
 
942
  st.subheader("2D & 3D Molecular Structures")
943
  for name, visual_html in res3.get('visuals', {}).items():
944
- st.html(visual_html)
 
945
 
946
 
947
  # --- Phase 4: Pre-clinical & RWE ---
@@ -1002,5 +1003,4 @@ with tab4:
1002
  st.dataframe(res4.get('reg_df', pd.DataFrame()), use_container_width=True, hide_index=True)
1003
 
1004
  st.subheader("Ethical AI Framework")
1005
- st.dataframe(res4.get('eth_df', pd.DataFrame()), use_container_width=True, hide_index=True)
1006
-
 
33
  warnings.filterwarnings('ignore')
34
 
35
  # --- Page Configuration ---
36
+ # CORRECTED: Removed the 'theme' argument to prevent errors and rely on custom CSS.
37
  st.set_page_config(
38
  page_title="AI Drug Discovery Pipeline",
39
  page_icon="🔬",
40
  layout="wide",
41
+ initial_sidebar_state="collapsed",
42
  )
43
 
44
  # Custom CSS for a professional, dark theme
 
157
  if not pdb_data:
158
  return None, "Cannot generate 3D view: No PDB data provided."
159
  try:
160
+ viewer = py3Dmol.view(width='100%', height=600)
 
161
  viewer.setBackgroundColor('#1C1C1C')
162
  viewer.addModel(pdb_data, "pdb")
163
  viewer.setStyle({'cartoon': {'color': 'spectrum', 'thickness': 0.8}})
 
448
  svg_2d = svg_2d.replace('fill:black', 'fill:white')
449
  svg_2d = svg_2d.replace('stroke:#000000', 'stroke:#FFFFFF')
450
  svg_2d = svg_2d.replace('fill:#000000', 'fill:#FFFFFF')
451
+ svg_2d = svg_2d.replace('stroke:#000', 'stroke="#FFF"')
452
  svg_2d = svg_2d.replace('fill:#000', 'fill="#FFF"')
453
  svg_2d = svg_2d.replace('stroke="rgb(0,0,0)"', 'stroke="rgb(255,255,255)"')
454
  svg_2d = svg_2d.replace('fill="rgb(0,0,0)"', 'fill="rgb(255,255,255)"')
455
  svg_2d = svg_2d.replace('stroke:rgb(0,0,0)', 'stroke:rgb(255,255,255)')
456
  svg_2d = svg_2d.replace('fill:rgb(0,0,0)', 'fill:rgb(255,255,255)')
457
  svg_2d = svg_2d.replace('color="black"', 'color="white"')
458
+ svg_2d = svg_2d.replace('color:#000000', 'color="#FFFFFF"')
459
+ svg_2d = svg_2d.replace('color:#000', 'color="#FFF"')
460
 
461
  # Aggressive regex-based fixes for all text elements
462
  # Remove any existing fill attributes from text elements and add white fill
 
487
  AllChem.MMFFOptimizeMolecule(mol_3d)
488
  sdf_data = Chem.MolToMolBlock(mol_3d)
489
 
490
+ viewer = py3Dmol.view(width=400, height=300)
 
491
  viewer.setBackgroundColor('#1C1C1C')
492
  viewer.addModel(sdf_data, "sdf")
493
  viewer.setStyle({'stick': {}, 'sphere': {'scale': 0.25}})
 
519
  return None, "Cannot generate interaction view: No PDB data provided."
520
 
521
  try:
522
+ viewer = py3Dmol.view(width='100%', height=650)
 
523
  viewer.setBackgroundColor('#1C1C1C')
524
 
525
  # Add the protein structure
 
793
  with p1_tabs[0]:
794
  st.subheader(f"3D Structure for PDB ID: {pdb_id_input}")
795
  if res1.get('protein_view'):
796
+ # CORRECTED: Use st.markdown with unsafe_allow_html=True to render the component.
797
+ st.markdown(res1['protein_view'], unsafe_allow_html=True)
798
  else:
799
  st.warning("Could not display 3D structure. Check PDB ID and logs.")
800
 
 
878
  with p2_tabs[1]:
879
  st.subheader(f"Simulated Interaction for PDB {p2_pdb_id} with Ligand {p2_ligand_resn}")
880
  if res2.get('interaction_view'):
881
+ # CORRECTED: Use st.markdown with unsafe_allow_html=True to render the component.
882
+ st.markdown(res2['interaction_view'], unsafe_allow_html=True)
883
  else:
884
  st.warning("Could not display interaction view. Check inputs and logs.")
885
 
 
941
 
942
  st.subheader("2D & 3D Molecular Structures")
943
  for name, visual_html in res3.get('visuals', {}).items():
944
+ # CORRECTED: Use st.markdown with unsafe_allow_html=True to render the component.
945
+ st.markdown(visual_html, unsafe_allow_html=True)
946
 
947
 
948
  # --- Phase 4: Pre-clinical & RWE ---
 
1003
  st.dataframe(res4.get('reg_df', pd.DataFrame()), use_container_width=True, hide_index=True)
1004
 
1005
  st.subheader("Ethical AI Framework")
1006
+ st.dataframe(res4.get('eth_df', pd.DataFrame()), use_container_width=True, hide_index=True)