Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update quant_base_module.py #462

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions proteobench/modules/quant_base/quant_base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ def write_json_local_development(self, temporary_datapoints: pd.DataFrame, datap

return os.path.join(self.t_dir_pr, "results.json")

def write_intermediate_raw(
self, dir: str, ident: str, input_file_path: str, result_performance: pd.DataFrame, param_loc
):
def write_intermediate_raw(self, dir: str, ident: str, input_file_obj, result_performance: pd.DataFrame, param_loc):
"""
Write intermediate and raw data to a directory.

Expand All @@ -368,8 +366,8 @@ def write_intermediate_raw(
Directory to write to.
ident : str
Identifier (e.g., hash) to create a subdirectory for this submission.
input_file_path : str
Location to temp file of raw-input
input_file_obj : file-like object
File-like object representing the raw input file (e.g., from Streamlit).
result_performance : pd.DataFrame
Result performance DataFrame to be saved.
param_loc : list of str
Expand All @@ -383,8 +381,13 @@ def write_intermediate_raw(
except Exception as e:
logging.warning(f"Could not create directory: {path_write}. Error: {e}")

# Save the input file-like object content to disk
input_file_path = os.path.join(path_write, "input_file_without_extension")
try:
shutil.copy(input_file_path, dir)
input_file_obj.seek(0) # Reset file pointer to the beginning
with open(input_file_path, "wb") as f:
f.write(input_file_obj.read()) # Read the content and write it to a file
logging.info(f"Input file saved to {input_file_path}")
except Exception as e:
logging.error(f"Failed to save input file to {input_file_path}. Error: {e}")

Expand Down