Spaces:
Running on Zero
Running on Zero
integrate download zip logic inside generation_with_input_config, remove gr.update
Browse files- app.py +2 -8
- utils/handle_files.py +4 -4
- utils/pipelines.py +6 -8
app.py
CHANGED
|
@@ -64,7 +64,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 64 |
|
| 65 |
""")
|
| 66 |
|
| 67 |
-
|
| 68 |
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".
|
| 69 |
|
| 70 |
# inputs from user
|
|
@@ -130,23 +130,17 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 130 |
|
| 131 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 132 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
| 133 |
-
|
| 134 |
-
|
| 135 |
|
| 136 |
#generation_event = run_btn.click(
|
| 137 |
# lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 138 |
# outputs=[run_btn, stop_btn]
|
| 139 |
#).then(
|
| 140 |
generation_event = run_btn.click(
|
| 141 |
-
generation_with_input_config, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration], outputs=[runtextbox,
|
| 142 |
).then(
|
| 143 |
update_batch_choices,
|
| 144 |
inputs=gen_results,
|
| 145 |
outputs=batch_dropdown
|
| 146 |
-
).then(
|
| 147 |
-
download_results_as_zip,
|
| 148 |
-
inputs=gen_directory,
|
| 149 |
-
outputs=output_file
|
| 150 |
)#.then(
|
| 151 |
# lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 152 |
# outputs=[run_btn, stop_btn]
|
|
|
|
| 64 |
|
| 65 |
""")
|
| 66 |
|
| 67 |
+
|
| 68 |
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".
|
| 69 |
|
| 70 |
# inputs from user
|
|
|
|
| 130 |
|
| 131 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 132 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
|
|
|
|
|
|
| 133 |
|
| 134 |
#generation_event = run_btn.click(
|
| 135 |
# lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 136 |
# outputs=[run_btn, stop_btn]
|
| 137 |
#).then(
|
| 138 |
generation_event = run_btn.click(
|
| 139 |
+
generation_with_input_config, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration], outputs=[runtextbox, gen_results, output_file]
|
| 140 |
).then(
|
| 141 |
update_batch_choices,
|
| 142 |
inputs=gen_results,
|
| 143 |
outputs=batch_dropdown
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
)#.then(
|
| 145 |
# lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 146 |
# outputs=[run_btn, stop_btn]
|
utils/handle_files.py
CHANGED
|
@@ -33,18 +33,18 @@ def download_results_as_zip(directory):
|
|
| 33 |
|
| 34 |
Parameters:
|
| 35 |
----------
|
| 36 |
-
directory: gr.State
|
| 37 |
Path to the directory containing generated results. None if generation has not been run yet.
|
| 38 |
|
| 39 |
Returns
|
| 40 |
-------
|
| 41 |
-
|
| 42 |
"""
|
| 43 |
if directory is None:
|
| 44 |
-
return
|
| 45 |
zip_path = f"{directory}.zip"
|
| 46 |
shutil.make_archive(directory, 'zip', directory)
|
| 47 |
-
return
|
| 48 |
|
| 49 |
|
| 50 |
def collect_outputs(gen_directory, num_batches, num_designs_per_batch):
|
|
|
|
| 33 |
|
| 34 |
Parameters:
|
| 35 |
----------
|
| 36 |
+
directory: gr.State or str
|
| 37 |
Path to the directory containing generated results. None if generation has not been run yet.
|
| 38 |
|
| 39 |
Returns
|
| 40 |
-------
|
| 41 |
+
str or None: Path to the created zip file if directory is valid, else None.
|
| 42 |
"""
|
| 43 |
if directory is None:
|
| 44 |
+
return None
|
| 45 |
zip_path = f"{directory}.zip"
|
| 46 |
shutil.make_archive(directory, 'zip', directory)
|
| 47 |
+
return zip_path
|
| 48 |
|
| 49 |
|
| 50 |
def collect_outputs(gen_directory, num_batches, num_designs_per_batch):
|
utils/pipelines.py
CHANGED
|
@@ -42,7 +42,7 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 42 |
|
| 43 |
|
| 44 |
if input_file is None:
|
| 45 |
-
return
|
| 46 |
elif pdb_file is None:
|
| 47 |
status_update = f"Running generation for {num_batches} batches of {num_designs_per_batch}\n job configuration uploaded from file {os.path.basename(input_file)}\n no scaffold/target provided"
|
| 48 |
else:
|
|
@@ -67,11 +67,9 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 67 |
command = f"rfd3 design inputs={input_file} out_dir={directory} n_batches={num_batches} diffusion_batch_size={num_designs_per_batch}"
|
| 68 |
if extra_args:
|
| 69 |
command += f" {extra_args}"
|
| 70 |
-
print(f"Running command: {command}")
|
| 71 |
status_update += f"\nRunning command: {command}."
|
| 72 |
start = perf_counter()
|
| 73 |
res = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
|
| 74 |
-
print("Command took", perf_counter() - start, "seconds to run.")
|
| 75 |
status_update += f"\nGeneration successful! Command took {perf_counter() - start:.2f} seconds to run."
|
| 76 |
|
| 77 |
|
|
@@ -86,13 +84,13 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 86 |
cif_path = os.path.join(directory, file_name)
|
| 87 |
pdb_path = mcif_gz_to_pdb(cif_path)
|
| 88 |
results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
|
| 93 |
except subprocess.CalledProcessError as e:
|
| 94 |
-
|
| 95 |
-
return gr.update(value=f"Generation failed:\n{e.stderr}"), None, None
|
| 96 |
|
| 97 |
|
| 98 |
#def generation_with_input_config_factory(max_duration):
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
if input_file is None:
|
| 45 |
+
return "Please ensure you have uploaded a configuration file: .yaml or .json", None, None
|
| 46 |
elif pdb_file is None:
|
| 47 |
status_update = f"Running generation for {num_batches} batches of {num_designs_per_batch}\n job configuration uploaded from file {os.path.basename(input_file)}\n no scaffold/target provided"
|
| 48 |
else:
|
|
|
|
| 67 |
command = f"rfd3 design inputs={input_file} out_dir={directory} n_batches={num_batches} diffusion_batch_size={num_designs_per_batch}"
|
| 68 |
if extra_args:
|
| 69 |
command += f" {extra_args}"
|
|
|
|
| 70 |
status_update += f"\nRunning command: {command}."
|
| 71 |
start = perf_counter()
|
| 72 |
res = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
|
|
|
|
| 73 |
status_update += f"\nGeneration successful! Command took {perf_counter() - start:.2f} seconds to run."
|
| 74 |
|
| 75 |
|
|
|
|
| 84 |
cif_path = os.path.join(directory, file_name)
|
| 85 |
pdb_path = mcif_gz_to_pdb(cif_path)
|
| 86 |
results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})
|
| 87 |
+
|
| 88 |
+
zip_path = download_results_as_zip(directory)
|
| 89 |
+
|
| 90 |
+
return status_update, results, zip_path
|
| 91 |
|
| 92 |
except subprocess.CalledProcessError as e:
|
| 93 |
+
return f"Generation failed:\n{e.stderr}", None, None
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
#def generation_with_input_config_factory(max_duration):
|