Spaces:
Running on Zero
Running on Zero
Revert "call rfd3 with process.Popen to allow cancellation" and do not pass subprocess to go back to working version
Browse filesThis reverts commit f8364c2c939323a000f5524e96fdc3653ed5d200.
- app.py +9 -5
- utils/pipelines.py +4 -48
app.py
CHANGED
|
@@ -13,7 +13,6 @@ from utils.pipelines import *
|
|
| 13 |
#from gradio_molecule3d import Molecule3D
|
| 14 |
from utils.handle_events import *
|
| 15 |
from utils.handle_files import *
|
| 16 |
-
import signal
|
| 17 |
|
| 18 |
download_weights()
|
| 19 |
|
|
@@ -132,13 +131,19 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 132 |
display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
|
| 133 |
display_state.value = "Please Select a Batch and Design number to show sequence"
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
generation_event = run_btn.click(
|
| 138 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 139 |
outputs=[run_btn, stop_btn]
|
| 140 |
).then(
|
| 141 |
-
|
| 142 |
).then(
|
| 143 |
update_batch_choices,
|
| 144 |
inputs=gen_results,
|
|
@@ -151,7 +156,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 151 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 152 |
outputs=[run_btn, stop_btn]
|
| 153 |
)
|
| 154 |
-
|
| 155 |
stop_btn.click(
|
| 156 |
lambda: gr.update(value="Generation cancelled by user."),
|
| 157 |
outputs=runtextbox,
|
|
@@ -178,6 +183,5 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 178 |
#visualize_btn.click(load_viewer, inputs=[batch_dropdown, design_dropdown, gen_results], outputs=viewer)
|
| 179 |
|
| 180 |
if __name__ == "__main__":
|
| 181 |
-
|
| 182 |
demo.queue()
|
| 183 |
demo.launch()
|
|
|
|
| 13 |
#from gradio_molecule3d import Molecule3D
|
| 14 |
from utils.handle_events import *
|
| 15 |
from utils.handle_files import *
|
|
|
|
| 16 |
|
| 17 |
download_weights()
|
| 18 |
|
|
|
|
| 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 |
+
def generate(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration):
|
| 135 |
+
if config_upload is None:
|
| 136 |
+
return gr.update(), None, None
|
| 137 |
+
else:
|
| 138 |
+
textbox_update, gen_directory, gen_results = generation_with_input_config(config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration)
|
| 139 |
+
print(textbox_update)
|
| 140 |
+
return textbox_update, gen_directory, gen_results
|
| 141 |
|
| 142 |
generation_event = run_btn.click(
|
| 143 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 144 |
outputs=[run_btn, stop_btn]
|
| 145 |
).then(
|
| 146 |
+
generate, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration], outputs=[runtextbox, gen_directory, gen_results]
|
| 147 |
).then(
|
| 148 |
update_batch_choices,
|
| 149 |
inputs=gen_results,
|
|
|
|
| 156 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 157 |
outputs=[run_btn, stop_btn]
|
| 158 |
)
|
| 159 |
+
|
| 160 |
stop_btn.click(
|
| 161 |
lambda: gr.update(value="Generation cancelled by user."),
|
| 162 |
outputs=runtextbox,
|
|
|
|
| 183 |
#visualize_btn.click(load_viewer, inputs=[batch_dropdown, design_dropdown, gen_results], outputs=viewer)
|
| 184 |
|
| 185 |
if __name__ == "__main__":
|
|
|
|
| 186 |
demo.queue()
|
| 187 |
demo.launch()
|
utils/pipelines.py
CHANGED
|
@@ -53,7 +53,6 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 53 |
directory = f"./outputs/generation_with_input_config/session_{session_hash}_{time_stamp}"
|
| 54 |
os.makedirs(directory, exist_ok=False)
|
| 55 |
|
| 56 |
-
process = None
|
| 57 |
try:
|
| 58 |
if pdb_file is not None:
|
| 59 |
# I need to do this because uploading files to a HF space stores each file in a separate temp directory so I need to copy them again to the same place.
|
|
@@ -71,37 +70,11 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 71 |
print(f"Running command: {command}")
|
| 72 |
status_update += f"\nRunning command: {command}."
|
| 73 |
start = perf_counter()
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
shell=True,
|
| 79 |
-
stdout=subprocess.PIPE,
|
| 80 |
-
stderr=subprocess.PIPE,
|
| 81 |
-
text=True,
|
| 82 |
-
preexec_fn=os.setsid, # For Unix-like systems, start a new process group
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
-
# Immediately yield to make process available in State
|
| 86 |
-
yield gr.update(value=status_update), gr.update(), gr.update()
|
| 87 |
-
|
| 88 |
-
# Poll the process - yield regularly to allow Gradio to stop calling the generator
|
| 89 |
-
while process.poll() is None:
|
| 90 |
-
time.sleep(2) # Wait before checking again
|
| 91 |
-
yield gr.update(value=status_update), gr.update(), gr.update()
|
| 92 |
-
|
| 93 |
-
# Get the output after process completes
|
| 94 |
-
stdout, stderr = process.communicate()
|
| 95 |
-
|
| 96 |
-
# Check if process succeeded
|
| 97 |
-
if process.returncode != 0:
|
| 98 |
-
raise subprocess.CalledProcessError(process.returncode, command, stdout, stderr)
|
| 99 |
-
|
| 100 |
-
elapsed_time = perf_counter() - start
|
| 101 |
-
print(f"Command took {elapsed_time:.2f} seconds to run.")
|
| 102 |
-
status_update += f"\nGeneration successful! Command took {elapsed_time:.2f} seconds to run."
|
| 103 |
|
| 104 |
-
# Collect results from output directory
|
| 105 |
results = []
|
| 106 |
for file_name in os.listdir(directory):
|
| 107 |
if file_name.endswith(".cif.gz"):
|
|
@@ -120,23 +93,6 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 120 |
except subprocess.CalledProcessError as e:
|
| 121 |
print("subprocess threw an error", e.stderr)
|
| 122 |
return gr.update(value=f"Generation failed:\n{e.stderr}"), None, None
|
| 123 |
-
|
| 124 |
-
except Exception as e:
|
| 125 |
-
# Handle cancellation or other errors - terminate the subprocess if it's still running
|
| 126 |
-
if process and process.poll() is None:
|
| 127 |
-
print(f"Terminating subprocess due to: {e}")
|
| 128 |
-
try:
|
| 129 |
-
os.killpg(os.getpgid(process.pid), 15) # SIGTERM to process group
|
| 130 |
-
except Exception:
|
| 131 |
-
process.terminate()
|
| 132 |
-
try:
|
| 133 |
-
process.wait(timeout=5) # Wait up to 5 seconds for graceful termination
|
| 134 |
-
except subprocess.TimeoutExpired:
|
| 135 |
-
try:
|
| 136 |
-
os.killpg(os.getpgid(process.pid), 9) # SIGKILL to process group
|
| 137 |
-
except Exception:
|
| 138 |
-
process.kill() # Force kill if killpg fails
|
| 139 |
-
raise # Re-raise the exception so Gradio knows the event was cancelled
|
| 140 |
|
| 141 |
|
| 142 |
#def generation_with_input_config_factory(max_duration):
|
|
|
|
| 53 |
directory = f"./outputs/generation_with_input_config/session_{session_hash}_{time_stamp}"
|
| 54 |
os.makedirs(directory, exist_ok=False)
|
| 55 |
|
|
|
|
| 56 |
try:
|
| 57 |
if pdb_file is not None:
|
| 58 |
# I need to do this because uploading files to a HF space stores each file in a separate temp directory so I need to copy them again to the same place.
|
|
|
|
| 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 |
|
|
|
|
| 78 |
results = []
|
| 79 |
for file_name in os.listdir(directory):
|
| 80 |
if file_name.endswith(".cif.gz"):
|
|
|
|
| 93 |
except subprocess.CalledProcessError as e:
|
| 94 |
print("subprocess threw an error", e.stderr)
|
| 95 |
return gr.update(value=f"Generation failed:\n{e.stderr}"), None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
#def generation_with_input_config_factory(max_duration):
|