Spaces:
Running on Zero
Running on Zero
remove redundant buttons and state handling, get random hash for output directory
Browse files- app.py +17 -17
- utils/handle_events.py +6 -10
- utils/pipelines.py +3 -2
app.py
CHANGED
|
@@ -65,8 +65,8 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 65 |
|
| 66 |
""")
|
| 67 |
|
| 68 |
-
config_ready = gr.State(None) # whether the config is ready for running generation, takes values None, "manual", or "upload"
|
| 69 |
-
scaffold_ready = gr.State(None) # whether the scaffold is ready for running generation, takes values None, "upload", or "no_input"
|
| 70 |
gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
|
| 71 |
gen_results = gr.State(None) # the results of the generation, which is a list of dicts where each dict contains batch number "batch", design number "design", path to cif file "cif_path", and path to pdb file "pdb_path".
|
| 72 |
|
|
@@ -75,17 +75,17 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 75 |
with gr.Column(scale=1): # Left half
|
| 76 |
gr.Markdown("Set up the configuration for your run through a valid yaml file. Choose the number of batches and designs per batch for your run.")
|
| 77 |
config_upload = gr.File(label="Config file: .yaml or .json", file_types=[".pdb", ".yaml", ".json"])
|
| 78 |
-
config_validation_btn = gr.Button("Validate Config")
|
| 79 |
-
config_textbox = gr.Textbox(label="Configuration status", value ="Waiting for config validation...")
|
| 80 |
|
| 81 |
|
| 82 |
with gr.Column(scale=1): # Right half
|
| 83 |
gr.Markdown("Upload your target/scaffold structure as a PDB file to condition the generation. Press 'No Scaffold/Target' if you want to run an unconditional generation.")
|
| 84 |
scaffold_upload = gr.File(label="Target/Scaffold PDB", file_types=[".pdb"])
|
| 85 |
-
with gr.Row():
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
scaffold_textbox = gr.Textbox(label="Scaffold/Target status", value ="Waiting for scaffold validation...")
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
num_designs_per_batch = gr.Number(
|
|
@@ -116,9 +116,9 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 116 |
|
| 117 |
|
| 118 |
# validate the configuration
|
| 119 |
-
config_validation_btn.click(validate_config_ready, inputs=config_upload, outputs=[config_textbox, config_ready])
|
| 120 |
-
scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
|
| 121 |
-
no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditional generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
|
| 122 |
|
| 123 |
output_file = gr.File(label="Download RFD3 results as zip", visible=True)
|
| 124 |
|
|
@@ -139,20 +139,20 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 139 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 140 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
| 141 |
|
| 142 |
-
def generate(
|
| 143 |
-
if
|
| 144 |
return None, None
|
| 145 |
-
if
|
| 146 |
gen_directory, gen_results = generation_with_input_config(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args)
|
| 147 |
return gen_directory, gen_results
|
| 148 |
-
if
|
| 149 |
gen_directory, gen_results = generation_with_input_config(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args)
|
| 150 |
return gen_directory, gen_results
|
| 151 |
else:
|
| 152 |
return None, None
|
| 153 |
|
| 154 |
-
run_btn.click(give_run_status, inputs=[
|
| 155 |
-
generate, inputs=[
|
| 156 |
).then(
|
| 157 |
update_batch_choices,
|
| 158 |
inputs=gen_results,
|
|
|
|
| 65 |
|
| 66 |
""")
|
| 67 |
|
| 68 |
+
#config_ready = gr.State(None) # whether the config is ready for running generation, takes values None, "manual", or "upload"
|
| 69 |
+
#scaffold_ready = gr.State(None) # whether the scaffold is ready for running generation, takes values None, "upload", or "no_input"
|
| 70 |
gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
|
| 71 |
gen_results = gr.State(None) # the results of the generation, which is a list of dicts where each dict contains batch number "batch", design number "design", path to cif file "cif_path", and path to pdb file "pdb_path".
|
| 72 |
|
|
|
|
| 75 |
with gr.Column(scale=1): # Left half
|
| 76 |
gr.Markdown("Set up the configuration for your run through a valid yaml file. Choose the number of batches and designs per batch for your run.")
|
| 77 |
config_upload = gr.File(label="Config file: .yaml or .json", file_types=[".pdb", ".yaml", ".json"])
|
| 78 |
+
#config_validation_btn = gr.Button("Validate Config")
|
| 79 |
+
#config_textbox = gr.Textbox(label="Configuration status", value ="Waiting for config validation...")
|
| 80 |
|
| 81 |
|
| 82 |
with gr.Column(scale=1): # Right half
|
| 83 |
gr.Markdown("Upload your target/scaffold structure as a PDB file to condition the generation. Press 'No Scaffold/Target' if you want to run an unconditional generation.")
|
| 84 |
scaffold_upload = gr.File(label="Target/Scaffold PDB", file_types=[".pdb"])
|
| 85 |
+
#with gr.Row():
|
| 86 |
+
# scaffold_validation_btn = gr.Button("Validate Scaffold")
|
| 87 |
+
# no_input_btn = gr.Button("No Scaffold/Target")
|
| 88 |
+
#scaffold_textbox = gr.Textbox(label="Scaffold/Target status", value ="Waiting for scaffold validation...")
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
num_designs_per_batch = gr.Number(
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
# validate the configuration
|
| 119 |
+
#config_validation_btn.click(validate_config_ready, inputs=config_upload, outputs=[config_textbox, config_ready])
|
| 120 |
+
#scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
|
| 121 |
+
#no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditional generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
|
| 122 |
|
| 123 |
output_file = gr.File(label="Download RFD3 results as zip", visible=True)
|
| 124 |
|
|
|
|
| 139 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 140 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
| 141 |
|
| 142 |
+
def generate(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args):
|
| 143 |
+
if config_upload is None or scaffold_upload is None:
|
| 144 |
return None, None
|
| 145 |
+
if config_upload is not None and scaffold_upload is None:
|
| 146 |
gen_directory, gen_results = generation_with_input_config(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args)
|
| 147 |
return gen_directory, gen_results
|
| 148 |
+
if config_upload is not None and scaffold_upload is not None:
|
| 149 |
gen_directory, gen_results = generation_with_input_config(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args)
|
| 150 |
return gen_directory, gen_results
|
| 151 |
else:
|
| 152 |
return None, None
|
| 153 |
|
| 154 |
+
run_btn.click(give_run_status, inputs=[num_batches, num_designs_per_batch, config_upload, scaffold_upload], outputs=runtextbox).then(
|
| 155 |
+
generate, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args], outputs=[gen_directory, gen_results]
|
| 156 |
).then(
|
| 157 |
update_batch_choices,
|
| 158 |
inputs=gen_results,
|
utils/handle_events.py
CHANGED
|
@@ -100,16 +100,12 @@ def validate_scaffold_ready_with_file(scaffold_upload):
|
|
| 100 |
else:
|
| 101 |
return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
|
| 102 |
|
| 103 |
-
def give_run_status(
|
| 104 |
"""
|
| 105 |
Once the user presses on the Run Generation button, this function checks whether both config and scaffold are ready, and gives a status message about the generation run that is about to happen. If both config and scaffold are not ready, it prompts the user to ensure they are both validated before running the generation.
|
| 106 |
|
| 107 |
Parameters:
|
| 108 |
----------
|
| 109 |
-
config_ready: gr.State
|
| 110 |
-
status string for config readiness, is "manual" if manual config is selected and valid, "upload" if upload config is selected and valid, and None if config is not ready for generation
|
| 111 |
-
scaffold_ready: gr.State
|
| 112 |
-
status string for scaffold readiness, is "upload" if scaffold file is uploaded and valid, "no_input" if no scaffold/target is selected for unconditioned generation, and None if scaffold is not ready for generation
|
| 113 |
num_batches: gr.Number
|
| 114 |
number of batches input by the user manually
|
| 115 |
num_designs_per_batch: gr.Number
|
|
@@ -125,11 +121,11 @@ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_b
|
|
| 125 |
|
| 126 |
|
| 127 |
"""
|
| 128 |
-
if
|
| 129 |
-
return gr.update(value="Please ensure
|
| 130 |
-
|
| 131 |
return gr.update(value=f"Running unconditional generation for {num_batches} batches of {num_designs_per_batch}, config uploaded from file {os.path.basename(config_upload)}")
|
| 132 |
-
|
| 133 |
-
return gr.update(value=f"Running conditional generation for {num_batches} batches of {num_designs_per_batch}, config uploaded from file {os.path.basename(config_upload)}, scaffold uploaded
|
| 134 |
else:
|
| 135 |
return gr.update(value=f"Not implemented yet")
|
|
|
|
| 100 |
else:
|
| 101 |
return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
|
| 102 |
|
| 103 |
+
def give_run_status(num_batches, num_designs_per_batch, config_upload, scaffold_upload):
|
| 104 |
"""
|
| 105 |
Once the user presses on the Run Generation button, this function checks whether both config and scaffold are ready, and gives a status message about the generation run that is about to happen. If both config and scaffold are not ready, it prompts the user to ensure they are both validated before running the generation.
|
| 106 |
|
| 107 |
Parameters:
|
| 108 |
----------
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
num_batches: gr.Number
|
| 110 |
number of batches input by the user manually
|
| 111 |
num_designs_per_batch: gr.Number
|
|
|
|
| 121 |
|
| 122 |
|
| 123 |
"""
|
| 124 |
+
if config_upload is None or scaffold_upload is None:
|
| 125 |
+
return gr.update(value="Please ensure you have uploaded a configuration file: .yaml or .json")
|
| 126 |
+
if config_upload is not None and scaffold_upload is None:
|
| 127 |
return gr.update(value=f"Running unconditional generation for {num_batches} batches of {num_designs_per_batch}, config uploaded from file {os.path.basename(config_upload)}")
|
| 128 |
+
if config_upload is not None and scaffold_upload is not None:
|
| 129 |
+
return gr.update(value=f"Running conditional generation for {num_batches} batches of {num_designs_per_batch}, config uploaded from file {os.path.basename(config_upload)}, scaffold uploaded as {os.path.basename(scaffold_upload)}")
|
| 130 |
else:
|
| 131 |
return gr.update(value=f"Not implemented yet")
|
utils/pipelines.py
CHANGED
|
@@ -10,6 +10,7 @@ from utils.handle_files import *
|
|
| 10 |
import sys
|
| 11 |
import shutil
|
| 12 |
from time import perf_counter
|
|
|
|
| 13 |
|
| 14 |
@spaces.GPU(duration=240)
|
| 15 |
def test_rfd3_from_notebook():
|
|
@@ -121,9 +122,9 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 121 |
|
| 122 |
"""
|
| 123 |
|
| 124 |
-
session_hash =
|
| 125 |
time_stamp = time.strftime("%Y-%m-%d-%H-%M-%S")
|
| 126 |
-
directory = f"./outputs/
|
| 127 |
os.makedirs(directory, exist_ok=False)
|
| 128 |
|
| 129 |
try:
|
|
|
|
| 10 |
import sys
|
| 11 |
import shutil
|
| 12 |
from time import perf_counter
|
| 13 |
+
import random
|
| 14 |
|
| 15 |
@spaces.GPU(duration=240)
|
| 16 |
def test_rfd3_from_notebook():
|
|
|
|
| 122 |
|
| 123 |
"""
|
| 124 |
|
| 125 |
+
session_hash = random.getrandbits(128)
|
| 126 |
time_stamp = time.strftime("%Y-%m-%d-%H-%M-%S")
|
| 127 |
+
directory = f"./outputs/generation_with_input_config/session_{session_hash}_{time_stamp}"
|
| 128 |
os.makedirs(directory, exist_ok=False)
|
| 129 |
|
| 130 |
try:
|