steveyu323 commited on
Commit
69d70b9
·
1 Parent(s): 5bd3c5c
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -1,29 +1,31 @@
1
  import gradio as gr
2
  import torch
3
- import torch.nn as nn
4
- from transformers import PreTrainedModel, PretrainedConfig
5
- from tape import ProteinBertForSequenceClassification, TAPETokenizer
6
  import re
 
 
7
 
8
  WHITESPACE_RE = re.compile(r"\s+")
9
 
10
  def sanitize(s):
11
  return WHITESPACE_RE.sub("", str(s).upper())
12
 
13
- # Load model directly (avoids trust_remote_code complexity in Spaces)
14
- # ckpt = torch.load("kinbert_v2_long.pt", map_location="cpu")
15
- # OR load from your hub repo:
16
- from huggingface_hub import hf_hub_download
17
- ckpt_path = hf_hub_download("steveyu323/kinbert_v2_long", "checkpoints/best.pt")
18
- ckpt = torch.load(ckpt_path, map_location="cpu")
 
19
 
 
 
20
  model = ProteinBertForSequenceClassification.from_pretrained("bert-base", num_labels=2)
21
- model.load_state_dict(ckpt["state_dict"])
 
22
  model.eval()
23
 
24
  tokenizer = TAPETokenizer(vocab="iupac")
25
- THRESHOLD = float(ckpt["threshold"])
26
- MAX_LEN = 1024
27
 
28
  def predict(kinase_seq, substrate_seq):
29
  kinase_seq = sanitize(kinase_seq)
@@ -60,9 +62,6 @@ demo = gr.Interface(
60
  ],
61
  title="KinBERT — Kinase–Substrate Interaction Classifier",
62
  description="Predicts whether a kinase will phosphorylate a given substrate sequence.",
63
- examples=[
64
- ["MGSSHHHHHHSSGENLYFQGH", "ARTKQTARKSTGGKAPRKQL"],
65
- ],
66
  )
67
 
68
  demo.launch()
 
1
  import gradio as gr
2
  import torch
3
+ import json
 
 
4
  import re
5
+ from huggingface_hub import hf_hub_download
6
+ from tape import ProteinBertForSequenceClassification, TAPETokenizer
7
 
8
  WHITESPACE_RE = re.compile(r"\s+")
9
 
10
  def sanitize(s):
11
  return WHITESPACE_RE.sub("", str(s).upper())
12
 
13
+ # Load config
14
+ config_path = hf_hub_download("steveyu323/kinbert_v2_long", "config.json")
15
+ with open(config_path) as f:
16
+ config_dict = json.load(f)
17
+
18
+ THRESHOLD = float(config_dict.get("threshold", 0.5))
19
+ MAX_LEN = int(config_dict.get("max_len", 1024))
20
 
21
+ # Load model
22
+ model_path = hf_hub_download("steveyu323/kinbert_v2_long", "pytorch_model.bin")
23
  model = ProteinBertForSequenceClassification.from_pretrained("bert-base", num_labels=2)
24
+ state_dict = torch.load(model_path, map_location="cpu")
25
+ model.load_state_dict(state_dict)
26
  model.eval()
27
 
28
  tokenizer = TAPETokenizer(vocab="iupac")
 
 
29
 
30
  def predict(kinase_seq, substrate_seq):
31
  kinase_seq = sanitize(kinase_seq)
 
62
  ],
63
  title="KinBERT — Kinase–Substrate Interaction Classifier",
64
  description="Predicts whether a kinase will phosphorylate a given substrate sequence.",
 
 
 
65
  )
66
 
67
  demo.launch()