Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,25 +92,90 @@ def predict(sequence_input):
|
|
| 92 |
# --- 5. 创建并启动 Gradio 界面 ---
|
| 93 |
valid_example_sequence = "CGKSFIWSSTLFKHKRIHTGEKPYKCEECGKAFNHSQILLHIRHKRMHT"[:49]# 简单用49个'A'作为示例,你可以替换成一个更有代表性的序列
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
#
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# 启动应用
|
| 116 |
demo.launch()
|
|
|
|
| 92 |
# --- 5. 创建并启动 Gradio 界面 ---
|
| 93 |
valid_example_sequence = "CGKSFIWSSTLFKHKRIHTGEKPYKCEECGKAFNHSQILLHIRHKRMHT"[:49]# 简单用49个'A'作为示例,你可以替换成一个更有代表性的序列
|
| 94 |
|
| 95 |
+
css = """
|
| 96 |
+
#main-container {
|
| 97 |
+
max-width: 80%;
|
| 98 |
+
margin: auto;
|
| 99 |
+
}
|
| 100 |
+
#navbar {
|
| 101 |
+
display: flex;
|
| 102 |
+
justify-content: space-between;
|
| 103 |
+
align-items: center;
|
| 104 |
+
padding: 1rem 1.5rem;
|
| 105 |
+
background-color: #f5f5f5;
|
| 106 |
+
border-bottom: 1px solid #e0e0e0;
|
| 107 |
+
}
|
| 108 |
+
#logo {
|
| 109 |
+
font-size: 1.5em;
|
| 110 |
+
font-weight: bold;
|
| 111 |
+
}
|
| 112 |
+
#nav-links a {
|
| 113 |
+
margin-left: 20px;
|
| 114 |
+
text-decoration: none;
|
| 115 |
+
color: #333;
|
| 116 |
+
font-weight: 500;
|
| 117 |
+
}
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
# 使用 gr.Blocks 构建更灵活的布局
|
| 121 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
| 122 |
+
|
| 123 |
+
# --- 第一部分: 导航栏 ---
|
| 124 |
+
# 使用 gr.HTML 来直接嵌入HTML代码
|
| 125 |
+
gr.HTML("""
|
| 126 |
+
<div id="navbar">
|
| 127 |
+
<div id="logo">DeepKmulti</div>
|
| 128 |
+
<div id="nav-links">
|
| 129 |
+
<a href="/">Home</a>
|
| 130 |
+
<a href="/about">About</a> <!-- 在Gradio中,这些链接是象征性的 -->
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
""")
|
| 134 |
+
|
| 135 |
+
# 在一个自定义的div容器中组织主要内容,以应用居中和宽度限制
|
| 136 |
+
with gr.Column(elem_id="main-container"):
|
| 137 |
+
|
| 138 |
+
# --- 第二部分: 标题和描述 ---
|
| 139 |
+
gr.Markdown(
|
| 140 |
+
"""
|
| 141 |
+
# CAFN Model Deployment: Multi-label Classifier for Lysine Modifications
|
| 142 |
+
Given a biological sequence as input, the model predicts the probability of it belonging to each of the four classes (Kac, Kcr, Kme, Ksucc).
|
| 143 |
+
|
| 144 |
+
**Important note: This model requires the input sequence to be 49 characters long.**
|
| 145 |
+
"""
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# --- 第三部分: 核心交互区 ---
|
| 149 |
+
with gr.Row():
|
| 150 |
+
with gr.Column(scale=2): # 左侧占2/3宽度
|
| 151 |
+
sequence_input = gr.Textbox(
|
| 152 |
+
lines=7,
|
| 153 |
+
label=" (Input Sequence)",
|
| 154 |
+
placeholder="Please paste your 49-length sequence here, making sure your lysine is in the middle..."
|
| 155 |
+
)
|
| 156 |
+
submit_button = gr.Button("Predict", variant="primary") # 添加一个明确的提交按钮
|
| 157 |
+
|
| 158 |
+
with gr.Column(scale=1): # 右侧占1/3宽度
|
| 159 |
+
prediction_output = gr.Label(
|
| 160 |
+
num_top_classes=4,
|
| 161 |
+
label=" (Prediction Probabilities)"
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
# --- 第四部分: 示例 ---
|
| 165 |
+
gr.Examples(
|
| 166 |
+
examples=[[valid_example_sequence]],
|
| 167 |
+
inputs=sequence_input,
|
| 168 |
+
label="Example Sequence (Click to use)"
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
# --- 逻辑绑定 ---
|
| 172 |
+
# 将点击按钮的事件与预测函数关联起来
|
| 173 |
+
submit_button.click(
|
| 174 |
+
fn=predict,
|
| 175 |
+
inputs=sequence_input,
|
| 176 |
+
outputs=prediction_output
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
|
| 180 |
# 启动应用
|
| 181 |
demo.launch()
|