| import torch |
| import numpy as np |
| from transformers import AutoModel, AutoConfig |
|
|
| class EndpointHandler: |
| def __init__(self, path=""): |
| |
| self.config = AutoConfig.from_pretrained(path, trust_remote_code=True) |
| self.model = AutoModel.from_pretrained(path, trust_remote_code=True) |
| |
| self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
| self.model.to(self.device).eval() |
|
|
| def __call__(self, data): |
| sequence = data.get("inputs", "") |
| target_len = 196608 |
| |
| |
| seq = sequence[:target_len].ljust(target_len, 'N') |
| |
| |
| mapping = {'A': [1,0,0,0], 'C': [0,1,0,0], 'G': [0,0,1,0], 'T': [0,0,0,1]} |
| one_hot = np.array([mapping.get(base.upper(), [0,0,0,0]) for base in seq], dtype=np.float32) |
| |
| |
| inputs = torch.from_numpy(one_hot).unsqueeze(0).to(self.device) |
| |
| with torch.no_grad(): |
| output = self.model(inputs) |
| |
| |
| human_out = output['human'] |
| |
| |
| |
| target_tracks = [4479, 4828, 5111] |
| |
| |
| result = human_out[:, :, target_tracks] |
| |
| |
| return result.cpu().numpy().tolist() |