Spaces:
Running on Zero
Running on Zero
integrate download_zip logics inside run_generation_folder
Browse files- app.py +1 -3
- space_utils/handle_files.py +4 -4
- space_utils/pipelines.py +6 -12
app.py
CHANGED
|
@@ -107,11 +107,9 @@ with gr.Blocks(title="") as demo:
|
|
| 107 |
gen_directory_multi = gr.State(value=None)
|
| 108 |
|
| 109 |
run_btn_multi.click(
|
| 110 |
-
run_generation_folder, inputs=[pdb_folder, num_batches_multi, num_designs_per_batch_multi, chains_to_design_multi, temperature_multi, extra_args_multi, max_duration], outputs=[runtextbox_multi, gen_directory_multi]
|
| 111 |
).then(
|
| 112 |
display_fasta, inputs=gen_directory_multi, outputs=fastatextbox_multi
|
| 113 |
-
).then(
|
| 114 |
-
download_results_as_zip, inputs=gen_directory_multi, outputs=output_file_multi
|
| 115 |
).then(
|
| 116 |
lambda gen_dir: gr.update(choices=os.listdir(os.path.join(gen_dir, "seqs"))) if gen_dir else gr.update(), inputs=gen_directory_multi, outputs=select_fasta_to_show
|
| 117 |
)
|
|
|
|
| 107 |
gen_directory_multi = gr.State(value=None)
|
| 108 |
|
| 109 |
run_btn_multi.click(
|
| 110 |
+
run_generation_folder, inputs=[pdb_folder, num_batches_multi, num_designs_per_batch_multi, chains_to_design_multi, temperature_multi, extra_args_multi, max_duration], outputs=[runtextbox_multi, gen_directory_multi, output_file_multi]
|
| 111 |
).then(
|
| 112 |
display_fasta, inputs=gen_directory_multi, outputs=fastatextbox_multi
|
|
|
|
|
|
|
| 113 |
).then(
|
| 114 |
lambda gen_dir: gr.update(choices=os.listdir(os.path.join(gen_dir, "seqs"))) if gen_dir else gr.update(), inputs=gen_directory_multi, outputs=select_fasta_to_show
|
| 115 |
)
|
space_utils/handle_files.py
CHANGED
|
@@ -39,15 +39,15 @@ def download_results_as_zip(directory):
|
|
| 39 |
|
| 40 |
Parameters:
|
| 41 |
----------
|
| 42 |
-
directory: gr.
|
| 43 |
Path to the directory containing generated results. None if generation has not been run yet.
|
| 44 |
|
| 45 |
Returns
|
| 46 |
-------
|
| 47 |
-
|
| 48 |
"""
|
| 49 |
if directory is None:
|
| 50 |
-
return
|
| 51 |
zip_path = f"{directory}.zip"
|
| 52 |
shutil.make_archive(directory, 'zip', directory)
|
| 53 |
-
return
|
|
|
|
| 39 |
|
| 40 |
Parameters:
|
| 41 |
----------
|
| 42 |
+
directory: str or gr.Path
|
| 43 |
Path to the directory containing generated results. None if generation has not been run yet.
|
| 44 |
|
| 45 |
Returns
|
| 46 |
-------
|
| 47 |
+
str: path to the created zip file for download, or None if no directory was provided.
|
| 48 |
"""
|
| 49 |
if directory is None:
|
| 50 |
+
return None
|
| 51 |
zip_path = f"{directory}.zip"
|
| 52 |
shutil.make_archive(directory, 'zip', directory)
|
| 53 |
+
return zip_path
|
space_utils/pipelines.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
import shutil
|
| 7 |
import json
|
| 8 |
import spaces
|
| 9 |
-
|
| 10 |
#def run_generation_single_pdb(pdb_file, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args):
|
| 11 |
#
|
| 12 |
# random_hash = random.getrandbits(128)
|
|
@@ -34,7 +34,7 @@ def get_duration(pdb_folder, num_batches, num_designs_per_batch, chains_to_desig
|
|
| 34 |
def run_generation_folder(pdb_folder, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args, max_duration):
|
| 35 |
|
| 36 |
if pdb_folder is None:
|
| 37 |
-
return "Please upload a folder of PDB files to run generation.", None
|
| 38 |
|
| 39 |
status_string = f"Running generation with batch size {num_designs_per_batch} and number of batches {num_batches} for {len(pdb_folder)} pdb files..."
|
| 40 |
|
|
@@ -77,15 +77,9 @@ def run_generation_folder(pdb_folder, num_batches, num_designs_per_batch, chains
|
|
| 77 |
res = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
|
| 78 |
status_string += "\nGeneration complete!"
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
except subprocess.CalledProcessError as e:
|
| 82 |
-
return status_string+ f"\nGeneration failed: \n{e.stderr}", None
|
| 83 |
-
|
| 84 |
-
#def ligandmpnn_endpoint(pdb_folder, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args, max_duration):
|
| 85 |
-
# output_dir, status_update = gr.State(value=None), gr.State(value ="Waiting for generation run...")
|
| 86 |
-
# output_file_multi = gr.File(label="Download")
|
| 87 |
-
# output_dir, status_update =
|
| 88 |
|
| 89 |
-
def ligandmpnn_endpoint(pdb_folder, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args, max_duration):
|
| 90 |
-
status_str, output_dir = run_generation_folder(pdb_folder, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args, max_duration)
|
| 91 |
-
return output_dir
|
|
|
|
| 6 |
import shutil
|
| 7 |
import json
|
| 8 |
import spaces
|
| 9 |
+
from space_utils.handle_files import display_fasta, download_results_as_zip
|
| 10 |
#def run_generation_single_pdb(pdb_file, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args):
|
| 11 |
#
|
| 12 |
# random_hash = random.getrandbits(128)
|
|
|
|
| 34 |
def run_generation_folder(pdb_folder, num_batches, num_designs_per_batch, chains_to_design, temperature, extra_args, max_duration):
|
| 35 |
|
| 36 |
if pdb_folder is None:
|
| 37 |
+
return "Please upload a folder of PDB files to run generation.", None, None
|
| 38 |
|
| 39 |
status_string = f"Running generation with batch size {num_designs_per_batch} and number of batches {num_batches} for {len(pdb_folder)} pdb files..."
|
| 40 |
|
|
|
|
| 77 |
res = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
|
| 78 |
status_string += "\nGeneration complete!"
|
| 79 |
|
| 80 |
+
zip_path = download_results_as_zip(out_dir)
|
| 81 |
+
|
| 82 |
+
return status_string, out_dir, zip_path
|
| 83 |
except subprocess.CalledProcessError as e:
|
| 84 |
+
return status_string+ f"\nGeneration failed: \n{e.stderr}", None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
|
|
|
|
|
|
|
|