gabboud commited on
Commit
f6a67e4
·
1 Parent(s): 7f14dfe

remove deprecated gr.File.name attribute

Browse files
Files changed (4) hide show
  1. app.py +1 -1
  2. utils/handle_events.py +6 -1
  3. utils/handle_files.py +33 -1
  4. utils/pipelines.py +1 -1
app.py CHANGED
@@ -130,7 +130,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
130
  gen_directory, gen_results = unconditional_generation(num_batches, num_designs_per_batch, length)
131
  return gen_directory, gen_results
132
 
133
- run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length], outputs=runtextbox).then(
134
  generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results]
135
  ).then(
136
  update_batch_choices,
 
130
  gen_directory, gen_results = unconditional_generation(num_batches, num_designs_per_batch, length)
131
  return gen_directory, gen_results
132
 
133
+ run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload], outputs=runtextbox).then(
134
  generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results]
135
  ).then(
136
  update_batch_choices,
utils/handle_events.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
 
3
  def update_batch_choices(result):
4
  """
@@ -106,7 +107,7 @@ def validate_scaffold_ready_with_file(scaffold_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
 
@@ -122,6 +123,8 @@ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_b
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
  -------
@@ -133,5 +136,7 @@ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_b
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")
 
1
  import gradio as gr
2
+ from utils.handle_files import *
3
 
4
  def update_batch_choices(result):
5
  """
 
107
  else:
108
  return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
109
 
110
+ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload):
111
  """
112
  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.
113
 
 
123
  number of designs per batch input by the user in the manual config, used for the generation
124
  length: gr.Number
125
  length input by the user in the manual config, used for the generation status message
126
+ config_upload: gr.File
127
+ uploaded config file, used for the generation status message if upload config is selected
128
 
129
  Returns:
130
  -------
 
136
  return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
137
  elif config_ready=="manual" and scaffold_ready=="no_input":
138
  return gr.update(value=f"Running unconditional generation with minimal configuration: {num_batches} batches of {num_designs_per_batch} designs each, length = {length} aa")
139
+ elif config_ready == "upload" and scaffold_ready == "no_input":
140
+ return gr.update(value=f"Running unconditional generation with uploaded config file {config_upload}")
141
  else:
142
  return gr.update(value=f"Not implemented yet")
utils/handle_files.py CHANGED
@@ -3,6 +3,9 @@ import os
3
  import shutil
4
  import gradio as gr
5
  import subprocess
 
 
 
6
 
7
  def mcif_gz_to_pdb(file_path: str) -> str:
8
  """
@@ -50,4 +53,33 @@ def collect_outputs(gen_directory, num_batches, num_designs_per_batch):
50
  file_list = subprocess.check_output(cmd, shell=True).decode()
51
  return file_list
52
  except Exception as e:
53
- return f"Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import shutil
4
  import gradio as gr
5
  import subprocess
6
+ import json
7
+ import yaml
8
+ from pathlib import Path
9
 
10
  def mcif_gz_to_pdb(file_path: str) -> str:
11
  """
 
53
  file_list = subprocess.check_output(cmd, shell=True).decode()
54
  return file_list
55
  except Exception as e:
56
+ return f"Error: {str(e)}"
57
+
58
+
59
+ def load_config(file_path: str | Path) -> dict | list:
60
+ """
61
+ Load YAML or JSON file into a Python object.
62
+
63
+ Args:
64
+ file_path: Path to the YAML or JSON file.
65
+
66
+ Returns:
67
+ Parsed Python object (dict, list, etc.).
68
+
69
+ Raises:
70
+ ValueError: If extension is not .yaml, .yml, or .json.
71
+ Exception: On parse errors.
72
+ """
73
+ path = Path(file_path)
74
+ if not path.exists():
75
+ raise FileNotFoundError(f"File not found: {file_path}")
76
+
77
+ ext = path.suffix.lower()
78
+ if ext in {'.yaml', '.yml'}:
79
+ with open(path, 'r', encoding='utf-8') as f:
80
+ return yaml.safe_load(f) # Secure loader [web:1][web:4]
81
+ elif ext == '.json':
82
+ with open(path, 'r', encoding='utf-8') as f:
83
+ return json.load(f) # Built-in JSON loader [web:12]
84
+ else:
85
+ raise ValueError(f"Unsupported extension: {ext}. Use .yaml, .yml, or .json.")
utils/pipelines.py CHANGED
@@ -124,7 +124,7 @@ def unconditional_generation_with_input_config(input_file):
124
 
125
  try:
126
 
127
- command = f"rfd3 design inputs={input_file.name} out_dir={directory}"
128
  print(f"Running command: {command}")
129
  subprocess.run(command, shell=True, check=True)
130
 
 
124
 
125
  try:
126
 
127
+ command = f"rfd3 design inputs={input_file} out_dir={directory}"
128
  print(f"Running command: {command}")
129
  subprocess.run(command, shell=True, check=True)
130