oucgc1996 commited on
Commit
c34757d
·
verified ·
1 Parent(s): e946f65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -136,24 +136,23 @@ def CTXGen(τ, g_num, length_range, progress=gr.Progress()):
136
  progress(count / gen_num, desc="Generating conotoxins...")
137
  return 'output.csv', f"Generated {count} conotoxins."
138
 
139
- # 定义 Gradio 界面
140
- iface = gr.Interface(
141
- fn=CTXGen,
142
- inputs=[
143
- gr.Slider(minimum=1, maximum=2, step=0.1, label="τ"),
144
- gr.Dropdown(choices=[1, 10, 100], label="Number of generations"),
145
- RangeSlider(minimum=8, maximum=50, step=1, value=(12, 17), label="Length range")
146
- ],
147
- outputs=[
148
- gr.File(label="Download generated conotoxins"),
149
- gr.Textbox(label="Progress")
150
- ],
151
- live=True
152
- )
153
-
154
- # 添加停止按钮
155
- stop_button = gr.Button("Stop Generation")
156
- stop_button.click(stop_generation, outputs=gr.Textbox(label="Status"))
157
 
158
  # 启动 Gradio 应用
159
- iface.launch()
 
136
  progress(count / gen_num, desc="Generating conotoxins...")
137
  return 'output.csv', f"Generated {count} conotoxins."
138
 
139
+ # 使用 gr.Blocks 构建界面
140
+ with gr.Blocks() as demo:
141
+ gr.Markdown("# Conotoxin Generation")
142
+ with gr.Row():
143
+ τ = gr.Slider(minimum=1, maximum=2, step=0.1, label="τ")
144
+ g_num = gr.Dropdown(choices=[1, 10, 100], label="Number of generations")
145
+ length_range = RangeSlider(minimum=8, maximum=50, step=1, value=(12, 17), label="Length range")
146
+ with gr.Row():
147
+ start_button = gr.Button("Start Generation")
148
+ stop_button = gr.Button("Stop Generation")
149
+ with gr.Row():
150
+ output_file = gr.File(label="Download generated conotoxins")
151
+ status_text = gr.Textbox(label="Status")
152
+
153
+ # 绑定事件
154
+ start_button.click(CTXGen, inputs=[τ, g_num, length_range], outputs=[output_file, status_text])
155
+ stop_button.click(stop_generation, outputs=status_text)
 
156
 
157
  # 启动 Gradio 应用
158
+ demo.launch()