gabboud commited on
Commit
0cd364e
·
1 Parent(s): 37d4d4b

include zip_file download logic on fold_all_jobs, remove gr.update returns

Browse files
Files changed (3) hide show
  1. app.py +1 -9
  2. utils/handle_files.py +3 -3
  3. utils/pipelines.py +9 -5
app.py CHANGED
@@ -62,8 +62,6 @@ with gr.Blocks(title="RFD3 Test") as demo:
62
  all taken from <a href="https://github.com/RosettaCommons/foundry/tree/production/models/rf3" target="_blank">RosettaCommons' foundry repository.</a>
63
  """)
64
 
65
- gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
66
-
67
  # inputs from user
68
  with gr.Row():
69
  with gr.Column(scale=1): # Left half
@@ -109,16 +107,10 @@ with gr.Blocks(title="RFD3 Test") as demo:
109
  runtextbox = gr.Textbox(label="Run status", value="Waiting for folding run...")
110
  output_file = gr.File(label="Download RF3 results as zip", visible=True)
111
 
112
-
113
 
114
  run_btn.click(
115
- fold_all_jobs, inputs=[job_upload, support_upload, num_predictions, early_stopping, diffusion_steps, max_duration], outputs=[runtextbox, gen_directory]
116
- ).then(
117
- download_results_as_zip,
118
- inputs=gen_directory,
119
- outputs=output_file
120
  )
121
-
122
 
123
 
124
  if __name__ == "__main__":
 
62
  all taken from <a href="https://github.com/RosettaCommons/foundry/tree/production/models/rf3" target="_blank">RosettaCommons' foundry repository.</a>
63
  """)
64
 
 
 
65
  # inputs from user
66
  with gr.Row():
67
  with gr.Column(scale=1): # Left half
 
107
  runtextbox = gr.Textbox(label="Run status", value="Waiting for folding run...")
108
  output_file = gr.File(label="Download RF3 results as zip", visible=True)
109
 
 
110
 
111
  run_btn.click(
112
+ fold_all_jobs, inputs=[job_upload, support_upload, num_predictions, early_stopping, diffusion_steps, max_duration], outputs=[runtextbox, output_file]
 
 
 
 
113
  )
 
114
 
115
 
116
  if __name__ == "__main__":
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
- gr.update: Gradio update object to trigger file download. If directory is None, returns an empty update.
42
  """
43
  if directory is None:
44
  return gr.update()
45
  zip_path = f"{directory}.zip"
46
  shutil.make_archive(directory, 'zip', directory)
47
- return gr.update(value=zip_path, visible=True)
48
 
49
 
50
 
 
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: path to the generated zip file, to be passed to gr.File for download.
42
  """
43
  if directory is None:
44
  return gr.update()
45
  zip_path = f"{directory}.zip"
46
  shutil.make_archive(directory, 'zip', directory)
47
+ return zip_path
48
 
49
 
50
 
utils/pipelines.py CHANGED
@@ -32,17 +32,19 @@ def fold_all_jobs(job_files, support_files, num_predictions, early_stopping, dif
32
  The pLDDT threshold for early stopping. If set to 0, early stopping is disabled.
33
  diffusion_steps: int
34
  The number of diffusion steps to use during generation. Higher values may improve structure quality but will increase runtime.
 
 
35
 
36
  Returns:
37
  -------
38
  textbox_update: gr.update,
39
  A gr.update object to update the textbox with the status of the generation. propagates subprocess errors to the textbox if the generation fails.
40
- directory: str,
41
- The path to the directory where the generated structures are saved.
42
  """
43
 
44
  if job_files is None:
45
- return gr.update(value="Please ensure you have uploaded at least one job file: .json, .pdb, or .cif"), None
46
  elif support_files is None:
47
  status_update = f"Creating {num_predictions} structure predictions per job.\n jobs uploaded {[os.path.basename(f.name) for f in job_files]}\nno support files uploaded."
48
  else:
@@ -68,8 +70,10 @@ def fold_all_jobs(job_files, support_files, num_predictions, early_stopping, dif
68
  print("Command took", perf_counter() - start, "seconds to run.")
69
  status_update += f"\nGeneration successful! Command took {perf_counter() - start:.2f} seconds to run."
70
 
71
- return gr.update(value=status_update), directory
 
 
72
 
73
  except subprocess.CalledProcessError as e:
74
  print("subprocess threw an error", e.stderr)
75
- return gr.update(value=f"Generation failed:\n{e.stderr}"), None
 
32
  The pLDDT threshold for early stopping. If set to 0, early stopping is disabled.
33
  diffusion_steps: int
34
  The number of diffusion steps to use during generation. Higher values may improve structure quality but will increase runtime.
35
+ max_duration: int
36
+ The maximum duration (in seconds) for the folding process. This is used to set the timeout for the Spaces GPU allocation on ZeroGPU.
37
 
38
  Returns:
39
  -------
40
  textbox_update: gr.update,
41
  A gr.update object to update the textbox with the status of the generation. propagates subprocess errors to the textbox if the generation fails.
42
+ zip_path: str or None
43
+ If generation is successful, returns the path to the generated zip file containing the results, which can be passed to gr.File for download. None if generation fails.
44
  """
45
 
46
  if job_files is None:
47
+ return "Please ensure you have uploaded at least one job file: .json, .pdb, or .cif", None
48
  elif support_files is None:
49
  status_update = f"Creating {num_predictions} structure predictions per job.\n jobs uploaded {[os.path.basename(f.name) for f in job_files]}\nno support files uploaded."
50
  else:
 
70
  print("Command took", perf_counter() - start, "seconds to run.")
71
  status_update += f"\nGeneration successful! Command took {perf_counter() - start:.2f} seconds to run."
72
 
73
+ zip_path = download_results_as_zip(directory)
74
+
75
+ return status_update, zip_path
76
 
77
  except subprocess.CalledProcessError as e:
78
  print("subprocess threw an error", e.stderr)
79
+ return f"Generation failed:\n{e.stderr}", None