sagawa commited on
Commit
ef0bf75
1 Parent(s): 6e3dfae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -25
app.py CHANGED
@@ -7,11 +7,12 @@ import torch
7
  from torch.utils.data import DataLoader
8
  from transformers import AutoTokenizer
9
 
10
- sys.path.append("/home/user/app/")
11
- from scripts.foldseek_util import get_struc_seq
12
- from scripts.utils import seed_everything
13
- from scripts.models import PLTNUM_PreTrainedModel
14
- from scripts.datasets import PLTNUMDataset
 
15
 
16
  class Config:
17
  batch_size = 2
@@ -23,6 +24,7 @@ class Config:
23
  task = "classification"
24
  sequence_col = "sequence"
25
 
 
26
  # Assuming 'predict_stability' is your function that predicts protein stability
27
  def predict_stability(cfg, model_choice, organism_choice, pdb_file=None, sequence=None):
28
  # Check if pdb_file is provided
@@ -50,7 +52,7 @@ def predict_stability(cfg, model_choice, organism_choice, pdb_file=None, sequenc
50
  return f"Predicted Stability using {model_choice} for {organism_choice}: Example Output with sequence {output}..."
51
  else:
52
  return "No valid input provided."
53
-
54
 
55
  def get_foldseek_seq(pdb_path):
56
  parsed_seqs = get_struc_seq(
@@ -108,8 +110,7 @@ def predict(cfg, sequence):
108
  outputs = {}
109
  outputs["raw prediction values"] = predictions
110
  outputs["binary prediction values"] = [1 if x > 0.5 else 0 for x in predictions]
111
- return outputs
112
-
113
 
114
 
115
  # Gradio Interface
@@ -120,32 +121,41 @@ with gr.Blocks() as demo:
120
  **Predict the protein half-life from its sequence or PDB file.**
121
  """
122
  )
123
-
124
- gr.Image("https://github.com/sagawatatsuya/PLTNUM/blob/main/model-image.png?raw=true", label="Model Image")
 
 
 
125
 
126
  # Model and Organism selection in the same row to avoid layout issues
127
  with gr.Row():
128
  model_choice = gr.Radio(
129
- choices=["SaProt", "ESM2"],
130
- label="Select PLTNUM's base model.",
131
- value="SaProt"
132
  )
133
  organism_choice = gr.Radio(
134
- choices=["Mouse", "Human"],
135
- label="Select the target organism.",
136
- value="Mouse"
137
  )
138
-
139
  with gr.Tabs():
140
  with gr.TabItem("Upload PDB File"):
141
  gr.Markdown("### Upload your PDB file:")
142
  pdb_file = gr.File(label="Upload PDB File")
143
-
144
  predict_button = gr.Button("Predict Stability")
145
- prediction_output = gr.Textbox(label="Stability Prediction", interactive=False)
 
 
 
 
 
 
 
 
146
 
147
- predict_button.click(fn=predict_stability, inputs=[model_choice, organism_choice, pdb_file], outputs=prediction_output)
148
-
149
  with gr.TabItem("Enter Protein Sequence"):
150
  gr.Markdown("### Enter the protein sequence:")
151
  sequence = gr.Textbox(
@@ -154,10 +164,16 @@ with gr.Blocks() as demo:
154
  lines=8,
155
  )
156
  predict_button = gr.Button("Predict Stability")
157
- prediction_output = gr.Textbox(label="Stability Prediction", interactive=False)
 
 
 
 
 
 
 
 
158
 
159
- predict_button.click(fn=predict_stability, inputs=[model_choice, organism_choice, sequence], outputs=prediction_output)
160
-
161
  gr.Markdown(
162
  """
163
  ### How to Use:
@@ -168,7 +184,7 @@ with gr.Blocks() as demo:
168
  - **Predict**: Click 'Predict Stability' to receive the prediction.
169
  """
170
  )
171
-
172
  gr.Markdown(
173
  """
174
  ### About the Tool
 
7
  from torch.utils.data import DataLoader
8
  from transformers import AutoTokenizer
9
 
10
+ sys.path.append("/home/user/app/scripts")
11
+ from foldseek_util import get_struc_seq
12
+ from utils import seed_everything
13
+ from models import PLTNUM_PreTrainedModel
14
+ from datasets import PLTNUMDataset
15
+
16
 
17
  class Config:
18
  batch_size = 2
 
24
  task = "classification"
25
  sequence_col = "sequence"
26
 
27
+
28
  # Assuming 'predict_stability' is your function that predicts protein stability
29
  def predict_stability(cfg, model_choice, organism_choice, pdb_file=None, sequence=None):
30
  # Check if pdb_file is provided
 
52
  return f"Predicted Stability using {model_choice} for {organism_choice}: Example Output with sequence {output}..."
53
  else:
54
  return "No valid input provided."
55
+
56
 
57
  def get_foldseek_seq(pdb_path):
58
  parsed_seqs = get_struc_seq(
 
110
  outputs = {}
111
  outputs["raw prediction values"] = predictions
112
  outputs["binary prediction values"] = [1 if x > 0.5 else 0 for x in predictions]
113
+ return outputs
 
114
 
115
 
116
  # Gradio Interface
 
121
  **Predict the protein half-life from its sequence or PDB file.**
122
  """
123
  )
124
+
125
+ gr.Image(
126
+ "https://github.com/sagawatatsuya/PLTNUM/blob/main/model-image.png?raw=true",
127
+ label="Model Image",
128
+ )
129
 
130
  # Model and Organism selection in the same row to avoid layout issues
131
  with gr.Row():
132
  model_choice = gr.Radio(
133
+ choices=["SaProt", "ESM2"],
134
+ label="Select PLTNUM's base model.",
135
+ value="SaProt",
136
  )
137
  organism_choice = gr.Radio(
138
+ choices=["Mouse", "Human"],
139
+ label="Select the target organism.",
140
+ value="Mouse",
141
  )
142
+
143
  with gr.Tabs():
144
  with gr.TabItem("Upload PDB File"):
145
  gr.Markdown("### Upload your PDB file:")
146
  pdb_file = gr.File(label="Upload PDB File")
147
+
148
  predict_button = gr.Button("Predict Stability")
149
+ prediction_output = gr.Textbox(
150
+ label="Stability Prediction", interactive=False
151
+ )
152
+
153
+ predict_button.click(
154
+ fn=predict_stability,
155
+ inputs=[model_choice, organism_choice, pdb_file],
156
+ outputs=prediction_output,
157
+ )
158
 
 
 
159
  with gr.TabItem("Enter Protein Sequence"):
160
  gr.Markdown("### Enter the protein sequence:")
161
  sequence = gr.Textbox(
 
164
  lines=8,
165
  )
166
  predict_button = gr.Button("Predict Stability")
167
+ prediction_output = gr.Textbox(
168
+ label="Stability Prediction", interactive=False
169
+ )
170
+
171
+ predict_button.click(
172
+ fn=predict_stability,
173
+ inputs=[model_choice, organism_choice, sequence],
174
+ outputs=prediction_output,
175
+ )
176
 
 
 
177
  gr.Markdown(
178
  """
179
  ### How to Use:
 
184
  - **Predict**: Click 'Predict Stability' to receive the prediction.
185
  """
186
  )
187
+
188
  gr.Markdown(
189
  """
190
  ### About the Tool