@@ -32,20 +32,14 @@ def upload_video_to_gcs(output_dir: str, video_path: str):
3232 bucket_name = parts [0 ]
3333 folder_name = parts [1 ] if len (parts ) > 1 else ''
3434
35- # Initialize the GCS client
3635 storage_client = storage .Client ()
37-
38- # Get the bucket object
3936 bucket = storage_client .bucket (bucket_name )
4037
41- # Define the source and destination paths
4238 source_file_path = f"./{ video_path } "
4339 destination_blob_name = os .path .join (folder_name , "videos" , video_path )
4440
45- # Create a blob object
4641 blob = bucket .blob (destination_blob_name )
4742
48- # Upload the file
4943 max_logging .log (f"Uploading { source_file_path } to { bucket_name } /{ destination_blob_name } ..." )
5044 blob .upload_from_filename (source_file_path )
5145 max_logging .log (f"Upload complete { source_file_path } ." )
@@ -54,13 +48,11 @@ def upload_video_to_gcs(output_dir: str, video_path: str):
5448 max_logging .log (f"An error occurred: { e } " )
5549
5650def delete_file (file_path : str ):
57- # Best practice: Check if the file exists before trying to delete it.
5851 if os .path .exists (file_path ):
5952 try :
6053 os .remove (file_path )
6154 max_logging .log (f"Successfully deleted file: { file_path } " )
6255 except OSError as e :
63- # This catches other issues like permission errors
6456 max_logging .log (f"Error deleting file '{ file_path } ': { e } " )
6557 else :
6658 max_logging .log (f"The file '{ file_path } ' does not exist." )
@@ -92,7 +84,7 @@ def inference_generate_video(config, pipeline, filename_prefix=""):
9284 export_to_video (videos [i ], video_path , fps = config .fps )
9385 if config .output_dir .startswith ("gs://" ):
9486 upload_video_to_gcs (config .output_dir , video_path )
95- # Delete local files to avoid storing too manys videoss
87+ # Delete local files to avoid storing too manys videos
9688 delete_file (f"./{ video_path } " )
9789 return
9890
0 commit comments