oucgc1996 commited on
Commit
f138db5
·
verified ·
1 Parent(s): 93d316a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -66,7 +66,7 @@ def CTXGen(τ, g_num, length_range):
66
  start_time = time.time()
67
  while count < gen_num:
68
  if is_stopped: # 检查是否停止
69
- yield pd.DataFrame(), f"Generation stopped. Generated {count} conotoxins."
70
 
71
  if time.time() - start_time > 1200:
72
  break
@@ -84,7 +84,7 @@ def CTXGen(τ, g_num, length_range):
84
 
85
  for i in range(length):
86
  if is_stopped: # 检查是否停止
87
- yield 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)
@@ -140,11 +140,12 @@ def CTXGen(τ, g_num, length_range):
140
  })
141
  out.to_csv("output.csv", index=False, encoding='utf-8-sig')
142
  count += 1
143
- yield out
144
- yield out
145
 
146
  # 使用 gr.Blocks 构建界面
147
  with gr.Blocks() as demo:
 
148
  with gr.Row():
149
  τ = gr.Slider(minimum=1, maximum=2, step=0.1, label="τ")
150
  g_num = gr.Dropdown(choices=[1, 10, 100], label="Number of generations")
@@ -158,8 +159,8 @@ with gr.Blocks() as demo:
158
  output_file = gr.File(label="Download generated conotoxins")
159
 
160
  # 绑定事件
161
- start_button.click(CTXGen, inputs=[τ, g_num, length_range], outputs=[output_df,output_file])
162
- stop_button.click(stop_generation, outputs=output_file)
163
 
164
  # 启动 Gradio 应用
165
  demo.launch()
 
66
  start_time = time.time()
67
  while count < gen_num:
68
  if is_stopped: # 检查是否停止
69
+ return pd.DataFrame(), "output.csv"
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(), "output.csv"
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)
 
140
  })
141
  out.to_csv("output.csv", index=False, encoding='utf-8-sig')
142
  count += 1
143
+ yield out, "output.csv"
144
+ return out, "output.csv"
145
 
146
  # 使用 gr.Blocks 构建界面
147
  with gr.Blocks() as demo:
148
+ gr.Markdown("# Conotoxin Generation")
149
  with gr.Row():
150
  τ = gr.Slider(minimum=1, maximum=2, step=0.1, label="τ")
151
  g_num = gr.Dropdown(choices=[1, 10, 100], label="Number of generations")
 
159
  output_file = gr.File(label="Download generated conotoxins")
160
 
161
  # 绑定事件
162
+ start_button.click(CTXGen, inputs=[τ, g_num, length_range], outputs=[output_df, output_file])
163
+ stop_button.click(stop_generation, outputs=None)
164
 
165
  # 启动 Gradio 应用
166
  demo.launch()