colbyford commited on
Commit
334043f
1 Parent(s): a346273

Add GPU detection

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import re, os
2
  from pathlib import Path
3
  import gradio as gr
 
4
 
5
  from evodiff.pretrained import OA_DM_38M, D3PM_UNIFORM_38M, MSA_OA_DM_MAXSUB
6
  from evodiff.generate import generate_oaardm, generate_d3pm
@@ -8,16 +9,22 @@ from evodiff.generate_msa import generate_query_oadm_msa_simple
8
  from evodiff.conditional_generation import inpaint_simple, generate_scaffold
9
 
10
 
 
 
 
 
 
 
11
  def make_uncond_seq(seq_len, model_type):
12
  if model_type == "EvoDiff-Seq-OADM 38M":
13
  checkpoint = OA_DM_38M()
14
  model, collater, tokenizer, scheme = checkpoint
15
- tokeinzed_sample, generated_sequence = generate_oaardm(model, tokenizer, int(seq_len), batch_size=1, device='cpu')
16
 
17
  if model_type == "EvoDiff-D3PM-Uniform 38M":
18
  checkpoint = D3PM_UNIFORM_38M(return_all=True)
19
  model, collater, tokenizer, scheme, timestep, Q_bar, Q = checkpoint
20
- tokeinzed_sample, generated_sequence = generate_d3pm(model, tokenizer, Q, Q_bar, timestep, int(seq_len), batch_size=1, device='cpu')
21
 
22
  return generated_sequence
23
 
@@ -26,7 +33,7 @@ def make_cond_seq(seq_len, msa_file, n_sequences, model_type):
26
  checkpoint = MSA_OA_DM_MAXSUB()
27
  model, collater, tokenizer, scheme = checkpoint
28
  print(f"MSA File Path: {msa_file.name}")
29
- tokeinzed_sample, generated_sequence = generate_query_oadm_msa_simple(msa_file.name, model, tokenizer, int(n_sequences), seq_length=int(seq_len), device='cpu', selection_type='random')
30
 
31
  return generated_sequence
32
 
@@ -34,7 +41,7 @@ def make_inpainted_idrs(sequence, start_idx, end_idx, model_type):
34
  if model_type == "EvoDiff-Seq":
35
  checkpoint = OA_DM_38M()
36
  model, collater, tokenizer, scheme = checkpoint
37
- sample, entire_sequence, generated_idr = inpaint_simple(model, sequence, int(start_idx), int(end_idx), tokenizer=tokenizer, device='cpu')
38
 
39
  generated_idr_output = {
40
  "original_sequence": sequence,
@@ -54,7 +61,7 @@ def make_scaffold_motifs(pdb_code, start_idx, end_idx, scaffold_length, model_ty
54
  # print("Folders in User Cache Directory:", os.listdir("/home/user/.cache"))
55
  start_idx = list(map(int, start_idx.strip('][').split(',')))
56
  end_idx = list(map(int, end_idx.strip('][').split(',')))
57
- generated_sequence, new_start_idx, new_end_idx = generate_scaffold(model, pdb_code, start_idx, end_idx, scaffold_length, data_top_dir, tokenizer, device='cpu')
58
 
59
  generated_scaffold_output = {
60
  "generated_sequence": generated_sequence,
@@ -100,7 +107,7 @@ idr_app = gr.Interface(
100
  ],
101
  outputs=["text"],
102
  title = "Inpainting IDRs",
103
- description="Inpaining a new region inside a given sequence using the `EvoDiff-Seq` model."
104
  )
105
 
106
  scaffold_app = gr.Interface(
@@ -133,14 +140,14 @@ with gr.Blocks() as edapp:
133
  gr.TabbedInterface([
134
  usg_app,
135
  csg_app,
136
- idr_app#,
137
- # scaffold_app
138
  ],
139
  [
140
  "Unconditional sequence generation",
141
  "Conditional generation",
142
- "Inpainting IDRs"#,
143
- # "Scaffolding functional motifs"
144
  ])
145
 
146
 
 
1
  import re, os
2
  from pathlib import Path
3
  import gradio as gr
4
+ import torch
5
 
6
  from evodiff.pretrained import OA_DM_38M, D3PM_UNIFORM_38M, MSA_OA_DM_MAXSUB
7
  from evodiff.generate import generate_oaardm, generate_d3pm
 
9
  from evodiff.conditional_generation import inpaint_simple, generate_scaffold
10
 
11
 
12
+ def get_device():
13
+ if torch.cuda.is_available():
14
+ return "cuda"
15
+ else:
16
+ return "cpu"
17
+
18
  def make_uncond_seq(seq_len, model_type):
19
  if model_type == "EvoDiff-Seq-OADM 38M":
20
  checkpoint = OA_DM_38M()
21
  model, collater, tokenizer, scheme = checkpoint
22
+ tokeinzed_sample, generated_sequence = generate_oaardm(model, tokenizer, int(seq_len), batch_size=1, device=get_device())
23
 
24
  if model_type == "EvoDiff-D3PM-Uniform 38M":
25
  checkpoint = D3PM_UNIFORM_38M(return_all=True)
26
  model, collater, tokenizer, scheme, timestep, Q_bar, Q = checkpoint
27
+ tokeinzed_sample, generated_sequence = generate_d3pm(model, tokenizer, Q, Q_bar, timestep, int(seq_len), batch_size=1, device=get_device())
28
 
29
  return generated_sequence
30
 
 
33
  checkpoint = MSA_OA_DM_MAXSUB()
34
  model, collater, tokenizer, scheme = checkpoint
35
  print(f"MSA File Path: {msa_file.name}")
36
+ tokeinzed_sample, generated_sequence = generate_query_oadm_msa_simple(msa_file.name, model, tokenizer, int(n_sequences), seq_length=int(seq_len), device=get_device(), selection_type='random')
37
 
38
  return generated_sequence
39
 
 
41
  if model_type == "EvoDiff-Seq":
42
  checkpoint = OA_DM_38M()
43
  model, collater, tokenizer, scheme = checkpoint
44
+ sample, entire_sequence, generated_idr = inpaint_simple(model, sequence, int(start_idx), int(end_idx), tokenizer=tokenizer, device=get_device())
45
 
46
  generated_idr_output = {
47
  "original_sequence": sequence,
 
61
  # print("Folders in User Cache Directory:", os.listdir("/home/user/.cache"))
62
  start_idx = list(map(int, start_idx.strip('][').split(',')))
63
  end_idx = list(map(int, end_idx.strip('][').split(',')))
64
+ generated_sequence, new_start_idx, new_end_idx = generate_scaffold(model, pdb_code, start_idx, end_idx, scaffold_length, data_top_dir, tokenizer, device=get_device())
65
 
66
  generated_scaffold_output = {
67
  "generated_sequence": generated_sequence,
 
107
  ],
108
  outputs=["text"],
109
  title = "Inpainting IDRs",
110
+ description="Inpainting a new region inside a given sequence using the `EvoDiff-Seq` model."
111
  )
112
 
113
  scaffold_app = gr.Interface(
 
140
  gr.TabbedInterface([
141
  usg_app,
142
  csg_app,
143
+ idr_app,
144
+ scaffold_app
145
  ],
146
  [
147
  "Unconditional sequence generation",
148
  "Conditional generation",
149
+ "Inpainting IDRs",
150
+ "Scaffolding functional motifs"
151
  ])
152
 
153