jackrui commited on
Commit
4b12912
·
1 Parent(s): 130b942

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -29
app.py CHANGED
@@ -16,14 +16,14 @@ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint1)
16
  class MyModel(nn.Module):
17
  def __init__(self):
18
  super().__init__()
19
- self.bert1 = EsmForSequenceClassification.from_pretrained(model_checkpoint1, num_labels=3000)#3000
20
  # for param in self.bert1.parameters():
21
  # param.requires_grad = False
22
  self.bn1 = nn.BatchNorm1d(256)
23
  self.bn2 = nn.BatchNorm1d(128)
24
  self.bn3 = nn.BatchNorm1d(64)
25
  self.relu = nn.LeakyReLU()
26
- self.fc1 = nn.Linear(3000, 256)
27
  self.fc2 = nn.Linear(256, 128)
28
  self.fc3 = nn.Linear(128, 64)
29
  self.output_layer = nn.Linear(64, 2)
@@ -75,41 +75,56 @@ def classify_sequence(sequence):
75
  else:
76
  return "Invalid Sequence"
77
 
 
78
  # 加载模型
79
  model = MyModel()
80
- model.load_state_dict(torch.load("best_model.pth", map_location=torch.device('cpu')),strict=False)
81
-
82
 
83
  if __name__ == "__main__":
84
- with gr.Blocks() as demo:
85
-
86
- gr.Markdown(
87
- """
88
-
89
- # Welcome to Antimicrobial Peptide Recognition Model
90
- This is an antimicrobial peptide recognition model derived from Diff-AMP, which is a branch of a comprehensive system integrating generation, recognition, and optimization. In this recognition model, you can simply input a sequence, and it will predict whether it is an antimicrobial peptide. Due to limited website capacity, we can only perform simple predictions.
91
- If you require large-scale computations, please contact my email at [email protected]. Feel free to reach out if you have any questions or inquiries.
92
 
93
- """)
 
94
 
95
- # 添加示例输入和输出
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  examples = [
97
- ["KLLKKLLKLWKKLLKKLK"],
98
- ["FLGLLFHGVHHVGKWIHGLIHGHH"],
99
- ["GLMSTLKGAATNAAVTLLNKLQCKLTGTC"]
100
- ]
101
 
102
- # 创建 Gradio 接口并应用美化样式和示例
103
  iface = gr.Interface(
104
- fn=classify_sequence,
105
- inputs="text",
106
- outputs="text",
107
- title="AMP Sequence Detector",
108
- examples=examples
109
- )
110
-
 
111
 
112
  demo.launch()
113
-
114
-
115
-
 
16
  class MyModel(nn.Module):
17
  def __init__(self):
18
  super().__init__()
19
+ self.bert1 = EsmForSequenceClassification.from_pretrained(model_checkpoint1, num_labels=512) # 3000
20
  # for param in self.bert1.parameters():
21
  # param.requires_grad = False
22
  self.bn1 = nn.BatchNorm1d(256)
23
  self.bn2 = nn.BatchNorm1d(128)
24
  self.bn3 = nn.BatchNorm1d(64)
25
  self.relu = nn.LeakyReLU()
26
+ self.fc1 = nn.Linear(512, 256)
27
  self.fc2 = nn.Linear(256, 128)
28
  self.fc3 = nn.Linear(128, 64)
29
  self.output_layer = nn.Linear(64, 2)
 
75
  else:
76
  return "Invalid Sequence"
77
 
78
+
79
  # 加载模型
80
  model = MyModel()
81
+ model.load_state_dict(torch.load("best_model.pth", map_location=torch.device('cpu')))
 
82
 
83
  if __name__ == "__main__":
84
+ title = """<h1 align="center">🔥AMP Sequence Detector</h1>"""
85
+ css = ".json {height: 527px; overflow: scroll;} .json-holder {height: 527px; overflow: scroll;}"
86
+ theme = gr.themes.Soft(primary_hue="zinc", secondary_hue="blue", neutral_hue="lime",
87
+ text_size=gr.themes.sizes.text_lg)
88
+ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;} #chatbot {height: 520px; overflow: auto;}""",
89
+ theme=theme) as demo:
 
 
90
 
91
+ gr.Markdown("<h1>Diff-AMP</h1>")
92
+ gr.HTML(title)
93
 
94
+
95
+ gr.Markdown(
96
+ "<p align='center' style='font-size: 20px;'>🔥Welcome to Antimicrobial Peptide Recognition Model. See our <a href='https://github.com/wrab12/diff-amp'>Project</a></p>")
97
+ gr.HTML(
98
+ '''<center><a href="https://huggingface.co/spaces/jackrui/diff-amp-AMP_Sequence_Detector?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></center>''')
99
+ gr.HTML(
100
+ '''<center>🌟Note: This is an antimicrobial peptide recognition model derived from Diff-AMP, which is a branch of a comprehensive system integrating generation, recognition, and optimization. In this recognition model, you can simply input a sequence, and it will predict whether it is an antimicrobial peptide. Due to limited website capacity, we can only perform simple predictions.
101
+ If you require large-scale computations, please contact my email at [email protected]. Feel free to reach out if you have any questions or inquiries.</center>''')
102
+
103
+ # gr.Markdown(
104
+ # """
105
+ #
106
+ # # Welcome to Antimicrobial Peptide Recognition Model
107
+ # This is an antimicrobial peptide recognition model derived from Diff-AMP, which is a branch of a comprehensive system integrating generation, recognition, and optimization. In this recognition model, you can simply input a sequence, and it will predict whether it is an antimicrobial peptide. Due to limited website capacity, we can only perform simple predictions.
108
+ # If you require large-scale computations, please contact my email at [email protected]. Feel free to reach out if you have any questions or inquiries.
109
+ #
110
+ # """)
111
+
112
+ # 添加示例输入和输出
113
  examples = [
114
+ ["QGLFFLGAKLFYLLTLFL"],
115
+ ["FLGLLFHGVHHVGKWIHGLIHGHH"],
116
+ ["GLMSTLKGAATNAAVTLLNKLQCKLTGTC"]
117
+ ]
118
 
119
+ # 创建 Gradio 接口并应用美化样式和示例
120
  iface = gr.Interface(
121
+ fn=classify_sequence,
122
+ inputs="text",
123
+ outputs="text",
124
+ # title="AMP Sequence Detector",
125
+ examples=examples
126
+ )
127
+ gr.Markdown(
128
+ "<p align='center'><img src='https://pic4.zhimg.com/v2-eb2a7c0e746e67d1768090eec74f6787_b.jpg'></p>")
129
 
130
  demo.launch()