Update app.py
Browse files
app.py
CHANGED
|
@@ -66,7 +66,7 @@ def CTXGen(τ, g_num, length_range, progress=gr.Progress()):
|
|
| 66 |
start_time = time.time()
|
| 67 |
while count < gen_num:
|
| 68 |
if is_stopped: # 检查是否停止
|
| 69 |
-
return
|
| 70 |
|
| 71 |
if time.time() - start_time > 1200:
|
| 72 |
break
|
|
@@ -84,7 +84,7 @@ def CTXGen(τ, g_num, length_range, progress=gr.Progress()):
|
|
| 84 |
|
| 85 |
for i in range(length):
|
| 86 |
if is_stopped: # 检查是否停止
|
| 87 |
-
return
|
| 88 |
|
| 89 |
_, idx_seq, idx_msa, attn_idx = get_paded_token_idx_gen(vocab_mlm, seq, new_seq)
|
| 90 |
idx_seq = torch.tensor(idx_seq).unsqueeze(0).to(device)
|
|
@@ -130,11 +130,19 @@ def CTXGen(τ, g_num, length_range, progress=gr.Progress()):
|
|
| 130 |
cls_probability_all.append(cls_probability)
|
| 131 |
act_pos_all.append(act_pos)
|
| 132 |
act_probability_all.append(act_probability)
|
| 133 |
-
out = pd.DataFrame({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
out.to_csv("output.csv", index=False, encoding='utf-8-sig')
|
| 135 |
count += 1
|
| 136 |
progress(count / gen_num, desc="Generating conotoxins...")
|
| 137 |
-
|
|
|
|
| 138 |
|
| 139 |
# 使用 gr.Blocks 构建界面
|
| 140 |
with gr.Blocks() as demo:
|
|
@@ -147,11 +155,13 @@ with gr.Blocks() as demo:
|
|
| 147 |
start_button = gr.Button("Start Generation")
|
| 148 |
stop_button = gr.Button("Stop Generation")
|
| 149 |
with gr.Row():
|
| 150 |
-
|
| 151 |
status_text = gr.Textbox(label="Status")
|
|
|
|
|
|
|
| 152 |
|
| 153 |
# 绑定事件
|
| 154 |
-
start_button.click(CTXGen, inputs=[τ, g_num, length_range], outputs=[
|
| 155 |
stop_button.click(stop_generation, outputs=status_text)
|
| 156 |
|
| 157 |
# 启动 Gradio 应用
|
|
|
|
| 66 |
start_time = time.time()
|
| 67 |
while count < gen_num:
|
| 68 |
if is_stopped: # 检查是否停止
|
| 69 |
+
return pd.DataFrame(), f"Generation stopped. Generated {count} conotoxins."
|
| 70 |
|
| 71 |
if time.time() - start_time > 1200:
|
| 72 |
break
|
|
|
|
| 84 |
|
| 85 |
for i in range(length):
|
| 86 |
if is_stopped: # 检查是否停止
|
| 87 |
+
return pd.DataFrame(), f"Generation stopped. Generated {count} conotoxins."
|
| 88 |
|
| 89 |
_, idx_seq, idx_msa, attn_idx = get_paded_token_idx_gen(vocab_mlm, seq, new_seq)
|
| 90 |
idx_seq = torch.tensor(idx_seq).unsqueeze(0).to(device)
|
|
|
|
| 130 |
cls_probability_all.append(cls_probability)
|
| 131 |
act_pos_all.append(act_pos)
|
| 132 |
act_probability_all.append(act_probability)
|
| 133 |
+
out = pd.DataFrame({
|
| 134 |
+
'Generated_seq': generated_seqs_FINAL,
|
| 135 |
+
'Subtype': cls_pos_all,
|
| 136 |
+
'Subtype_probability': cls_probability_all,
|
| 137 |
+
'Potency': act_pos_all,
|
| 138 |
+
'Potency_probability': act_probability_all,
|
| 139 |
+
'random_seed': seed
|
| 140 |
+
})
|
| 141 |
out.to_csv("output.csv", index=False, encoding='utf-8-sig')
|
| 142 |
count += 1
|
| 143 |
progress(count / gen_num, desc="Generating conotoxins...")
|
| 144 |
+
yield out, f"Generated {count} conotoxins."
|
| 145 |
+
return out, f"Generated {count} conotoxins."
|
| 146 |
|
| 147 |
# 使用 gr.Blocks 构建界面
|
| 148 |
with gr.Blocks() as demo:
|
|
|
|
| 155 |
start_button = gr.Button("Start Generation")
|
| 156 |
stop_button = gr.Button("Stop Generation")
|
| 157 |
with gr.Row():
|
| 158 |
+
output_df = gr.DataFrame(label="Generated Conotoxins")
|
| 159 |
status_text = gr.Textbox(label="Status")
|
| 160 |
+
with gr.Row():
|
| 161 |
+
output_file = gr.File(label="Download generated conotoxins")
|
| 162 |
|
| 163 |
# 绑定事件
|
| 164 |
+
start_button.click(CTXGen, inputs=[τ, g_num, length_range], outputs=[output_df, status_text], live=True)
|
| 165 |
stop_button.click(stop_generation, outputs=status_text)
|
| 166 |
|
| 167 |
# 启动 Gradio 应用
|