Tonic commited on
Commit
f74eb0b
·
unverified ·
1 Parent(s): 1f1f2d8

add api call

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -1,16 +1,11 @@
1
  import gradio as gr
2
  import py3Dmol
3
  import io
4
- import torch
5
  import numpy as np
6
  import os
7
  import traceback
8
  import spaces
9
- # # Install ESM
10
- # os.system("pip install esm")
11
-
12
- from huggingface_hub import login
13
- from esm.models.esm3 import ESM3
14
  from esm.sdk.api import ESM3InferenceClient, ESMProtein, GenerationConfig
15
  from esm.utils.structure.protein_chain import ProteinChain
16
  from Bio.Data import PDBData
@@ -18,14 +13,16 @@ import biotite.structure as bs
18
  from biotite.structure.io import pdb
19
  from esm.utils import residue_constants as RC
20
 
21
- # Login to Hugging Face Hub
22
- hf_token = os.environ.get("HUGGINGFACE_TOKEN")
23
- if not hf_token:
24
- raise ValueError("HUGGINGFACE_TOKEN environment variable is not set")
25
- login(token=hf_token)
26
-
27
  # Initialize the model
28
- model: ESM3InferenceClient = ESM3.from_pretrained("esm3-open").to("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
 
 
 
 
 
29
 
30
  amino3to1 = {
31
  'ALA': 'A', 'CYS': 'C', 'ASP': 'D', 'GLU': 'E', 'PHE': 'F',
@@ -122,7 +119,7 @@ def get_protein(pdb_file) -> ESMProtein:
122
  def add_noise_to_coordinates(protein: ESMProtein, noise_level: float) -> ESMProtein:
123
  """Add Gaussian noise to the atom positions of the protein."""
124
  coordinates = protein.coordinates
125
- noise = torch.randn_like(coordinates) * noise_level
126
  noisy_coordinates = coordinates + noise
127
  return ESMProtein(sequence=protein.sequence, coordinates=noisy_coordinates)
128
 
 
1
  import gradio as gr
2
  import py3Dmol
3
  import io
 
4
  import numpy as np
5
  import os
6
  import traceback
7
  import spaces
8
+ from esm.sdk import client
 
 
 
 
9
  from esm.sdk.api import ESM3InferenceClient, ESMProtein, GenerationConfig
10
  from esm.utils.structure.protein_chain import ProteinChain
11
  from Bio.Data import PDBData
 
13
  from biotite.structure.io import pdb
14
  from esm.utils import residue_constants as RC
15
 
 
 
 
 
 
 
16
  # Initialize the model
17
+ token = os.environ.get("ESM_API_TOKEN")
18
+ if not token:
19
+ raise ValueError("ESM_API_TOKEN environment variable is not set")
20
+
21
+ model = client(
22
+ model="esm3-medium-2024-03",
23
+ url="https://forge.evolutionaryscale.ai",
24
+ token=token,
25
+ )
26
 
27
  amino3to1 = {
28
  'ALA': 'A', 'CYS': 'C', 'ASP': 'D', 'GLU': 'E', 'PHE': 'F',
 
119
  def add_noise_to_coordinates(protein: ESMProtein, noise_level: float) -> ESMProtein:
120
  """Add Gaussian noise to the atom positions of the protein."""
121
  coordinates = protein.coordinates
122
+ noise = np.random.randn(*coordinates.shape) * noise_level
123
  noisy_coordinates = coordinates + noise
124
  return ESMProtein(sequence=protein.sequence, coordinates=noisy_coordinates)
125