Spaces:
Running on Zero
Running on Zero
modularize event handling
Browse files- app.py +0 -15
- utils/handle_events.py +31 -1
- utils/handle_files.py +43 -0
- utils/pipelines.py +0 -19
app.py
CHANGED
|
@@ -119,21 +119,6 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 119 |
|
| 120 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 121 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
| 122 |
-
|
| 123 |
-
def download_results_as_zip(directory):
|
| 124 |
-
if directory is None:
|
| 125 |
-
return gr.update()
|
| 126 |
-
zip_path = f"{directory}.zip"
|
| 127 |
-
shutil.make_archive(directory, 'zip', directory)
|
| 128 |
-
return gr.update(value=zip_path, visible=True)
|
| 129 |
-
|
| 130 |
-
def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 131 |
-
if config_ready is None or scaffold_ready is None:
|
| 132 |
-
return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
|
| 133 |
-
elif config_ready=="manual" and scaffold_ready=="no_input":
|
| 134 |
-
return gr.update(value=f"Running unconditional generation with minimal configuration: {num_batches} batches of {num_designs_per_batch} designs each, length = {length} aa")
|
| 135 |
-
else:
|
| 136 |
-
return gr.update(value=f"Not implemented yet")
|
| 137 |
|
| 138 |
def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 139 |
if config_ready is None or scaffold_ready is None:
|
|
|
|
| 119 |
|
| 120 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 121 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 124 |
if config_ready is None or scaffold_ready is None:
|
utils/handle_events.py
CHANGED
|
@@ -104,4 +104,34 @@ def validate_scaffold_ready_with_file(scaffold_upload):
|
|
| 104 |
if scaffold_upload is not None:
|
| 105 |
return "Scaffold file uploaded and valid!", "upload"
|
| 106 |
else:
|
| 107 |
-
return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
if scaffold_upload is not None:
|
| 105 |
return "Scaffold file uploaded and valid!", "upload"
|
| 106 |
else:
|
| 107 |
+
return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
|
| 108 |
+
|
| 109 |
+
def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length):
|
| 110 |
+
"""
|
| 111 |
+
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.
|
| 112 |
+
|
| 113 |
+
Parameters:
|
| 114 |
+
----------
|
| 115 |
+
config_ready: gr.State
|
| 116 |
+
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
|
| 117 |
+
scaffold_ready: gr.State
|
| 118 |
+
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
|
| 119 |
+
num_batches: gr.Number
|
| 120 |
+
number of batches input by the user in the manual config, used for the generation status message
|
| 121 |
+
num_designs_per_batch: gr.Number
|
| 122 |
+
number of designs per batch input by the user in the manual config, used for the generation
|
| 123 |
+
length: gr.Number
|
| 124 |
+
length input by the user in the manual config, used for the generation status message
|
| 125 |
+
|
| 126 |
+
Returns:
|
| 127 |
+
-------
|
| 128 |
+
gr.update: Gradio update object to update the generation status message in the UI about to be run. If both config and scaffold are not ready, returns an update with a message prompting the user to ensure they are both validated before running the generation.
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
"""
|
| 132 |
+
if config_ready is None or scaffold_ready is None:
|
| 133 |
+
return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
|
| 134 |
+
elif config_ready=="manual" and scaffold_ready=="no_input":
|
| 135 |
+
return gr.update(value=f"Running unconditional generation with minimal configuration: {num_batches} batches of {num_designs_per_batch} designs each, length = {length} aa")
|
| 136 |
+
else:
|
| 137 |
+
return gr.update(value=f"Not implemented yet")
|
utils/handle_files.py
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gemmi
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def mcif_gz_to_pdb(file_path: str) -> str:
|
| 7 |
+
"""
|
| 8 |
+
Converts a .mcif.gz file to pdb and saves it to the same directory. Returns the path to the pdb file.
|
| 9 |
+
|
| 10 |
+
Parameters:
|
| 11 |
+
----------
|
| 12 |
+
file_path: str,
|
| 13 |
+
Path to the .mcif.gz file.
|
| 14 |
+
|
| 15 |
+
Returns
|
| 16 |
+
-------
|
| 17 |
+
str: path to the generated pdb file.
|
| 18 |
+
"""
|
| 19 |
+
st = gemmi.read_structure(file_path)
|
| 20 |
+
st.setup_entities() # Recommended for consistent entity handling [web:18]
|
| 21 |
+
pdb_path = file_path.replace(".cif.gz", ".pdb")
|
| 22 |
+
st.write_minimal_pdb(pdb_path)
|
| 23 |
+
return pdb_path
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def download_results_as_zip(directory):
|
| 27 |
+
"""
|
| 28 |
+
Check that an output directory is specified, then creates a zip file of the directory for download.
|
| 29 |
+
|
| 30 |
+
Parameters:
|
| 31 |
+
----------
|
| 32 |
+
directory: gr.State
|
| 33 |
+
Path to the directory containing generated results. None if generation has not been run yet.
|
| 34 |
+
|
| 35 |
+
Returns
|
| 36 |
+
-------
|
| 37 |
+
gr.update: Gradio update object to trigger file download. If directory is None, returns an empty update.
|
| 38 |
+
"""
|
| 39 |
+
if directory is None:
|
| 40 |
+
return gr.update()
|
| 41 |
+
zip_path = f"{directory}.zip"
|
| 42 |
+
shutil.make_archive(directory, 'zip', directory)
|
| 43 |
+
return gr.update(value=zip_path, visible=True)
|
utils/pipelines.py
CHANGED
|
@@ -6,7 +6,6 @@ import os
|
|
| 6 |
import spaces
|
| 7 |
import subprocess
|
| 8 |
import gzip
|
| 9 |
-
import gemmi
|
| 10 |
from utils.handle_files import *
|
| 11 |
|
| 12 |
|
|
@@ -89,21 +88,3 @@ def collect_outputs(gen_directory, num_batches, num_designs_per_batch):
|
|
| 89 |
return f"Error: {str(e)}"
|
| 90 |
|
| 91 |
|
| 92 |
-
def mcif_gz_to_pdb(file_path: str) -> str:
|
| 93 |
-
"""
|
| 94 |
-
Converts a .mcif.gz file to pdb and saves it to the same directory. Returns the path to the pdb file.
|
| 95 |
-
|
| 96 |
-
Parameters:
|
| 97 |
-
----------
|
| 98 |
-
file_path: str,
|
| 99 |
-
Path to the .mcif.gz file.
|
| 100 |
-
|
| 101 |
-
Returns
|
| 102 |
-
-------
|
| 103 |
-
str: path to the generated pdb file.
|
| 104 |
-
"""
|
| 105 |
-
st = gemmi.read_structure(file_path)
|
| 106 |
-
st.setup_entities() # Recommended for consistent entity handling [web:18]
|
| 107 |
-
pdb_path = file_path.replace(".cif.gz", ".pdb")
|
| 108 |
-
st.write_minimal_pdb(pdb_path)
|
| 109 |
-
return pdb_path
|
|
|
|
| 6 |
import spaces
|
| 7 |
import subprocess
|
| 8 |
import gzip
|
|
|
|
| 9 |
from utils.handle_files import *
|
| 10 |
|
| 11 |
|
|
|
|
| 88 |
return f"Error: {str(e)}"
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|