Zhaohan-Meng commited on
Commit
abb17a0
·
verified ·
1 Parent(s): b8ba622

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -390,7 +390,7 @@ def _format_component_table(
390
  )
391
 
392
  return (
393
- "<h4 style='margin:12px 0 6px'></h4>"
394
  "<table style='border-collapse:collapse;margin:6px 0 16px;width:100%'>"
395
  "<thead><tr style='background:#f5f5f5'>"
396
  "<th style='border:1px solid #ddd;padding:6px'>Protein range</th>"
@@ -540,11 +540,15 @@ def visualize_attention_and_ranges(
540
  # --------------------------------------------------
541
  # Connected components (visual coherence)
542
  # --------------------------------------------------
 
 
 
543
  components = _connected_components_2d(mask_top)
 
544
  ranges_html = _format_component_table(
545
  components,
546
- p_tokens,
547
- d_tokens,
548
  mode=mode,
549
  )
550
 
@@ -857,17 +861,25 @@ def inference_cb(prot_seq, drug_seq, head_choice, topk_choice, mode_choice):
857
  # ------------------------------
858
  # Parse mode (pair vs residue)
859
  # ------------------------------
860
- mode_choice = str(mode_choice).lower()
861
-
862
- if "residue" in mode_choice:
863
  mode = "residue"
864
  topk_pairs = 1
865
  topk_residues = min(20, topk)
 
 
 
 
 
 
866
  else:
 
867
  mode = "pair"
868
  topk_pairs = topk
869
  topk_residues = 1
870
 
 
871
  # ------------------------------
872
  # Visualisation
873
  # ------------------------------
@@ -1011,8 +1023,12 @@ h1{
1011
  margin: 0 auto;
1012
  justify-content: center;
1013
  }
 
 
 
1014
  """
1015
  with gr.Blocks() as demo:
 
1016
  gr.Markdown("<h1>ExplainBind: Token-level Protein–Ligand Interaction Visualiser</h1>")
1017
  gr.Markdown(
1018
  '<p class="subtle">'
@@ -1021,8 +1037,6 @@ with gr.Blocks() as demo:
1021
  '</p>'
1022
  )
1023
 
1024
-
1025
- # ===== Loscalzo logo + group name =====
1026
  gr.HTML(f"""
1027
  <div class="loscalzo-block">
1028
  <img src="data:image/png;base64,{LOSCAZLO_B64}"
 
390
  )
391
 
392
  return (
393
+ "<h4 style='margin:12px 0 6px'>Highlighted Binding site</h4>"
394
  "<table style='border-collapse:collapse;margin:6px 0 16px;width:100%'>"
395
  "<thead><tr style='background:#f5f5f5'>"
396
  "<th style='border:1px solid #ddd;padding:6px'>Protein range</th>"
 
540
  # --------------------------------------------------
541
  # Connected components (visual coherence)
542
  # --------------------------------------------------
543
+ p_tokens_orig = p_tokens.copy()
544
+ d_tokens_orig = d_tokens.copy()
545
+
546
  components = _connected_components_2d(mask_top)
547
+
548
  ranges_html = _format_component_table(
549
  components,
550
+ p_tokens_orig,
551
+ d_tokens_orig,
552
  mode=mode,
553
  )
554
 
 
861
  # ------------------------------
862
  # Parse mode (pair vs residue)
863
  # ------------------------------
864
+ mode_choice_clean = str(mode_choice).strip()
865
+
866
+ if mode_choice_clean == "Top-K residues":
867
  mode = "residue"
868
  topk_pairs = 1
869
  topk_residues = min(20, topk)
870
+
871
+ elif mode_choice_clean == "Top-K residues-atom pairs":
872
+ mode = "pair"
873
+ topk_pairs = topk
874
+ topk_residues = 1
875
+
876
  else:
877
+ # fallback
878
  mode = "pair"
879
  topk_pairs = topk
880
  topk_residues = 1
881
 
882
+
883
  # ------------------------------
884
  # Visualisation
885
  # ------------------------------
 
1023
  margin: 0 auto;
1024
  justify-content: center;
1025
  }
1026
+
1027
+
1028
+ }
1029
  """
1030
  with gr.Blocks() as demo:
1031
+
1032
  gr.Markdown("<h1>ExplainBind: Token-level Protein–Ligand Interaction Visualiser</h1>")
1033
  gr.Markdown(
1034
  '<p class="subtle">'
 
1037
  '</p>'
1038
  )
1039
 
 
 
1040
  gr.HTML(f"""
1041
  <div class="loscalzo-block">
1042
  <img src="data:image/png;base64,{LOSCAZLO_B64}"