Spaces:
Running on Zero
Running on Zero
do not pass subprocess object to gradio State
Browse files- app.py +2 -13
- utils/pipelines.py +5 -5
app.py
CHANGED
|
@@ -67,7 +67,6 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 67 |
|
| 68 |
gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
|
| 69 |
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".
|
| 70 |
-
process = gr.State(None) # to store the subprocess.Popen object for the generation process, used to terminate the process when the stop button is clicked.
|
| 71 |
|
| 72 |
# inputs from user
|
| 73 |
with gr.Row():
|
|
@@ -139,7 +138,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 139 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 140 |
outputs=[run_btn, stop_btn]
|
| 141 |
).then(
|
| 142 |
-
generation_with_input_config, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration], outputs=[runtextbox, gen_directory, gen_results
|
| 143 |
).then(
|
| 144 |
update_batch_choices,
|
| 145 |
inputs=gen_results,
|
|
@@ -153,18 +152,8 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 153 |
outputs=[run_btn, stop_btn]
|
| 154 |
)
|
| 155 |
|
| 156 |
-
def stop_generation(proc_state):
|
| 157 |
-
#if proc_state is not None and proc_state.poll() is None:
|
| 158 |
-
# try:
|
| 159 |
-
# # Kill whole process group so child processes die too
|
| 160 |
-
# os.killpg(os.getpgid(proc_state.pid), signal.SIGTERM)
|
| 161 |
-
# except Exception:
|
| 162 |
-
# proc_state.terminate()
|
| 163 |
-
return gr.update(value="Generation cancelled by user.")
|
| 164 |
-
|
| 165 |
stop_btn.click(
|
| 166 |
-
|
| 167 |
-
inputs=process,
|
| 168 |
outputs=runtextbox,
|
| 169 |
cancels=[generation_event]
|
| 170 |
).then(
|
|
|
|
| 67 |
|
| 68 |
gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
|
| 69 |
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".
|
|
|
|
| 70 |
|
| 71 |
# inputs from user
|
| 72 |
with gr.Row():
|
|
|
|
| 138 |
lambda: (gr.update(visible=False), gr.update(visible=True)),
|
| 139 |
outputs=[run_btn, stop_btn]
|
| 140 |
).then(
|
| 141 |
+
generation_with_input_config, inputs=[config_upload, scaffold_upload, num_batches, num_designs_per_batch, extra_args, max_duration], outputs=[runtextbox, gen_directory, gen_results]
|
| 142 |
).then(
|
| 143 |
update_batch_choices,
|
| 144 |
inputs=gen_results,
|
|
|
|
| 152 |
outputs=[run_btn, stop_btn]
|
| 153 |
)
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
stop_btn.click(
|
| 156 |
+
lambda: gr.update(value="Generation cancelled by user."),
|
|
|
|
| 157 |
outputs=runtextbox,
|
| 158 |
cancels=[generation_event]
|
| 159 |
).then(
|
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 gr.update(value="Please ensure you have uploaded a configuration file: .yaml or .json"), gr.update(), gr.update()
|
| 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:
|
|
@@ -83,12 +83,12 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 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()
|
|
@@ -115,11 +115,11 @@ def generation_with_input_config(input_file, pdb_file, num_batches, num_designs_
|
|
| 115 |
results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})
|
| 116 |
|
| 117 |
print(results)
|
| 118 |
-
return gr.update(value=status_update), directory, results
|
| 119 |
|
| 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
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
if input_file is None:
|
| 45 |
+
return gr.update(value="Please ensure you have uploaded a configuration file: .yaml or .json"), gr.update(), gr.update()
|
| 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:
|
|
|
|
| 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()
|
|
|
|
| 115 |
results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})
|
| 116 |
|
| 117 |
print(results)
|
| 118 |
+
return gr.update(value=status_update), directory, results
|
| 119 |
|
| 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
|