44
44
45
45
from collections import defaultdict
46
46
47
- import py7zr
47
+ from py7zr import Bad7zFile , SevenZipFile
48
48
import gdown
49
49
import os
50
50
import glob
@@ -70,15 +70,27 @@ def unzip_weights(archive_path, output_dir):
70
70
for fname in volume_files :
71
71
with open (fname , 'rb' ) as infile :
72
72
outfile .write (infile .read ())
73
-
74
73
print ("Created single archive file: " , archive_path )
75
74
76
- with py7zr .SevenZipFile (archive_path , mode = 'r' ) as z :
77
- z .extractall (path = output_dir )
75
+ try :
76
+ # this should extract the archive into .h5 file
77
+ with SevenZipFile (archive_path , mode = 'r' ) as z :
78
+ z .extractall (path = output_dir )
79
+ except Bad7zFile as e :
80
+ print (f"Extraction failed: { e } " )
81
+ print ("Falling back to using 7z command line tool" )
82
+ os .system (f"7z e { archive_path } .001 -o{ output_dir } " )
83
+ except Exception as e :
84
+ print (f"Extraction failed: { e } " )
85
+ print ("Could not extract the weights archive using 7z command line tool. Please make sure it is installed and available in the PATH." )
86
+ print ("You should probably be able to install 7z by running `sudo apt install p7zip-full`" )
78
87
79
88
# remove 7z archive
80
89
os .remove (archive_path )
81
90
91
+ print ("Extracted weights to: " , output_dir )
92
+ print ("Successfully extracted weights! (this is only done once)" )
93
+
82
94
def fetch_and_unzip_google_drive_link (gdrive_link , output_dir ):
83
95
"""
84
96
Fetches a shared file from a Google Drive link and extracts it from 7-zip format.
@@ -103,7 +115,7 @@ def fetch_and_unzip_google_drive_link(gdrive_link, output_dir):
103
115
# Extract the downloaded file
104
116
extracted_files = []
105
117
try :
106
- with py7zr . SevenZipFile (output_file , mode = 'r' ) as z :
118
+ with SevenZipFile (output_file , mode = 'r' ) as z :
107
119
z .extractall (path = output_dir )
108
120
extracted_files = os .listdir (output_dir )
109
121
print (f'Extracted files: { extracted_files } ' )
0 commit comments