Spaces:
Running on Zero
Running on Zero
complex input first test
Browse files
app.py
CHANGED
|
@@ -32,42 +32,114 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 32 |
This space allows you to run backbone generation jobs using Hugging Face's hardware and download the results!
|
| 33 |
|
| 34 |
|
| 35 |
-
<u>Image Source</u>: Butcher J, Krishna R, Mitra R, Brent RI, Li Y, Corley N, Kim PT, Funk J, Mathis S, Salike S, Muraishi A, Eisenach H, Thompson TR, Chen J, Politanska Y, Sehgal E, Coventry B, Zhang O, Qiang B, Didi K, Kazman M, DiMaio F, Baker D. De novo Design of All-atom Biomolecular Interactions with RFdiffusion3. bioRxiv [Preprint]. 2025 Nov 19:2025.09.18.676967. doi: 10.1101/2025.09.18.676967. PMID: 41000976; PMCID: PMC12458353.""")
|
| 36 |
|
| 37 |
|
| 38 |
gr.Image("assets/overview_rfd3_baker.png", width=600)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
gr.Markdown("Unconditional generation of backbones")
|
| 42 |
with gr.Row():
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
gen_directory = gr.State(None)
|
| 66 |
gen_results = gr.State(None)
|
| 67 |
-
gen_btn = gr.Button("Run Unconditional Generation")
|
| 68 |
output_file = gr.File(label="Download RFD3 results as zip", visible=True)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
# Section to inspect PDB of generated structures
|
| 72 |
with gr.Row():
|
| 73 |
batch_dropdown = gr.Dropdown(
|
|
@@ -91,8 +163,27 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 91 |
zip_path = f"{directory}.zip"
|
| 92 |
shutil.make_archive(directory, 'zip', directory)
|
| 93 |
return gr.update(value=zip_path, visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
update_batch_choices,
|
| 97 |
inputs=gen_results,
|
| 98 |
outputs=batch_dropdown).then(
|
|
@@ -108,8 +199,6 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
#def load_viewer(batch, design, result):
|
| 114 |
# if batch is None or design is None:
|
| 115 |
# return gr.update()
|
|
|
|
| 32 |
This space allows you to run backbone generation jobs using Hugging Face's hardware and download the results!
|
| 33 |
|
| 34 |
|
| 35 |
+
<u>Image and Model Source</u>: Butcher J, Krishna R, Mitra R, Brent RI, Li Y, Corley N, Kim PT, Funk J, Mathis S, Salike S, Muraishi A, Eisenach H, Thompson TR, Chen J, Politanska Y, Sehgal E, Coventry B, Zhang O, Qiang B, Didi K, Kazman M, DiMaio F, Baker D. De novo Design of All-atom Biomolecular Interactions with RFdiffusion3. bioRxiv [Preprint]. 2025 Nov 19:2025.09.18.676967. doi: 10.1101/2025.09.18.676967. PMID: 41000976; PMCID: PMC12458353.""")
|
| 36 |
|
| 37 |
|
| 38 |
gr.Image("assets/overview_rfd3_baker.png", width=600)
|
| 39 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
tab_selected = gr.State("upload")
|
| 43 |
+
config_ready = gr.State(None)
|
| 44 |
+
scaffold_ready = gr.State(None)
|
| 45 |
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
+
with gr.Column(scale=1): # Left half
|
| 48 |
+
gr.Markdown("Set up the configuration for your run through a valid yaml file or by manually setting minimal parameters for an unconditional run.")
|
| 49 |
+
with gr.Tabs() as config_tabs:
|
| 50 |
+
with gr.TabItem("Upload Config"):
|
| 51 |
+
config_upload = gr.File(label="PDB + Config", file_types=[".pdb", ".yaml", ".json"])
|
| 52 |
+
with gr.TabItem("Manual Config"):
|
| 53 |
+
num_designs_per_batch = gr.Number(
|
| 54 |
+
value=2,
|
| 55 |
+
label="Number of Designs per Batch",
|
| 56 |
+
precision=0,
|
| 57 |
+
minimum=1,
|
| 58 |
+
maximum=8
|
| 59 |
+
)
|
| 60 |
+
num_batches = gr.Number(
|
| 61 |
+
value=5,
|
| 62 |
+
label="Number of Batches",
|
| 63 |
+
precision=0,
|
| 64 |
+
minimum=1,
|
| 65 |
+
maximum=10
|
| 66 |
+
)
|
| 67 |
+
length = gr.Number(
|
| 68 |
+
value=40,
|
| 69 |
+
label="Length of Protein (number of residues)",
|
| 70 |
+
precision=0,
|
| 71 |
+
minimum=10,
|
| 72 |
+
maximum=200
|
| 73 |
+
)
|
| 74 |
+
config_validation_btn = gr.Button("Validate Config")
|
| 75 |
+
config_textbox = gr.Textbox(value ="Waiting for config validation...")
|
| 76 |
+
|
| 77 |
+
with gr.Column(scale=1): # Right half
|
| 78 |
+
gr.Markdown("Upload your target/scaffold structure as a PDB file to condition the generation. Press no input if you want to run an unconditional generation.")
|
| 79 |
+
with gr.Tabs():
|
| 80 |
+
with gr.TabItem("Scaffold PDB"):
|
| 81 |
+
scaffold_upload = gr.File(label="Target/Scaffold PDB", file_types=[".pdb"])
|
| 82 |
+
with gr.Row():
|
| 83 |
+
scaffold_validation_btn = gr.Button("Validate Scaffold")
|
| 84 |
+
no_input_btn = gr.Button("No Scaffold/Target")
|
| 85 |
+
scaffold_textbox = gr.Textbox(value ="Waiting for scaffold validation...")
|
| 86 |
+
run_btn = gr.Button("Run Generation", variant="primary")
|
| 87 |
+
runtextbox = gr.Textbox(value="Waiting for generation run...")
|
| 88 |
+
|
| 89 |
+
config_tabs.select(lambda tab_selected: "upload" if tab_selected == "manual" else "manual", inputs=tab_selected, outputs=tab_selected)
|
| 90 |
+
|
| 91 |
+
def validate_config_ready(tab_selected, config_upload):
|
| 92 |
+
if tab_selected == "manual":
|
| 93 |
+
return "Manual parameters selected and valid!", "manual"
|
| 94 |
+
elif tab_selected == "upload" and config_upload is None:
|
| 95 |
+
return "Please upload a config file or switch to manual config for uncondition generation.", None
|
| 96 |
+
elif tab_selected == "upload" and config_upload is not None:
|
| 97 |
+
return "Config file uploaded and valid!", "upload"
|
| 98 |
+
|
| 99 |
+
config_validation_btn.click(validate_config_ready, inputs=[tab_selected, config_upload], outputs=[config_textbox, config_ready])
|
| 100 |
+
|
| 101 |
+
def validate_scaffold_ready_with_file(scaffold_upload):
|
| 102 |
+
if scaffold_upload is not None:
|
| 103 |
+
return "Scaffold file uploaded and valid!", "upload"
|
| 104 |
+
else:
|
| 105 |
+
return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditioned generation.", None
|
| 106 |
+
|
| 107 |
+
scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
|
| 108 |
+
no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditioned generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
|
| 109 |
+
|
| 110 |
+
#run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready], outputs=runtextbox)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
#gr.Markdown("Unconditional generation of backbones")
|
| 114 |
+
#with gr.Row():
|
| 115 |
+
# num_designs_per_batch = gr.Number(
|
| 116 |
+
# value=2,
|
| 117 |
+
# label="Number of Designs per Batch",
|
| 118 |
+
# precision=0,
|
| 119 |
+
# minimum=1,
|
| 120 |
+
# maximum=8
|
| 121 |
+
# )
|
| 122 |
+
# num_batches = gr.Number(
|
| 123 |
+
# value=5,
|
| 124 |
+
# label="Number of Batches",
|
| 125 |
+
# precision=0,
|
| 126 |
+
# minimum=1,
|
| 127 |
+
# maximum=10
|
| 128 |
+
# )
|
| 129 |
+
# length = gr.Number(
|
| 130 |
+
# value=40,
|
| 131 |
+
# label="Length of Protein (number of residues)",
|
| 132 |
+
# precision=0,
|
| 133 |
+
# minimum=10,
|
| 134 |
+
# maximum=200
|
| 135 |
+
# )
|
| 136 |
|
| 137 |
gen_directory = gr.State(None)
|
| 138 |
gen_results = gr.State(None)
|
| 139 |
+
#gen_btn = gr.Button("Run Unconditional Generation")
|
| 140 |
output_file = gr.File(label="Download RFD3 results as zip", visible=True)
|
| 141 |
+
#
|
| 142 |
+
#
|
| 143 |
# Section to inspect PDB of generated structures
|
| 144 |
with gr.Row():
|
| 145 |
batch_dropdown = gr.Dropdown(
|
|
|
|
| 163 |
zip_path = f"{directory}.zip"
|
| 164 |
shutil.make_archive(directory, 'zip', directory)
|
| 165 |
return gr.update(value=zip_path, visible=True)
|
| 166 |
+
|
| 167 |
+
def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 168 |
+
if config_ready is None or scaffold_ready is None:
|
| 169 |
+
return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
|
| 170 |
+
elif config_ready=="manual" and scaffold_ready=="no_input":
|
| 171 |
+
return gr.update(value=f"Running unconditional generation with minimal configuration: {num_batches} batches of {num_designs_per_batch} designs each, length = {length} aa")
|
| 172 |
+
else:
|
| 173 |
+
return gr.update(value=f"Not implemented yet")
|
| 174 |
+
|
| 175 |
+
def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 176 |
+
if config_ready is None or scaffold_ready is None:
|
| 177 |
+
return None, None
|
| 178 |
+
if config_ready=="manual" and scaffold_ready=="no_input":
|
| 179 |
+
gen_directory, gen_results = unconditional_generation(num_batches, num_designs_per_batch, length)
|
| 180 |
+
return gen_directory, gen_results
|
| 181 |
+
|
| 182 |
+
run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length], outputs=runtextbox).then(
|
| 183 |
+
generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results]
|
| 184 |
+
)
|
| 185 |
|
| 186 |
+
run_btn.click(unconditional_generation, inputs=[num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results]).then(
|
| 187 |
update_batch_choices,
|
| 188 |
inputs=gen_results,
|
| 189 |
outputs=batch_dropdown).then(
|
|
|
|
| 199 |
|
| 200 |
|
| 201 |
|
|
|
|
|
|
|
| 202 |
#def load_viewer(batch, design, result):
|
| 203 |
# if batch is None or design is None:
|
| 204 |
# return gr.update()
|