Spaces:
r3gm
/
Running

r3gm commited on
Commit
18c71e6
1 Parent(s): 50f814b

Update easy_infer.py

Browse files
Files changed (1) hide show
  1. easy_infer.py +15 -0
easy_infer.py CHANGED
@@ -117,10 +117,23 @@ def find_folder_parent(search_dir, folder_name):
117
  return None
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  def download_from_url(url):
122
  parent_path = find_folder_parent(".", "pretrained_v2")
123
  zips_path = os.path.join(parent_path, 'zips')
 
124
 
125
  if url != '':
126
  print(i18n("Downloading the file: ") + f"{url}")
@@ -211,6 +224,8 @@ def download_from_url(url):
211
  os.chdir('./zips')
212
  wget.download(url)
213
 
 
 
214
  os.chdir(parent_path)
215
  print(i18n("Full download"))
216
  return "downloaded"
 
117
  return None
118
 
119
 
120
+ def delete_large_files(directory_path, max_size_megabytes):
121
+ for filename in os.listdir(directory_path):
122
+ file_path = os.path.join(directory_path, filename)
123
+ if os.path.isfile(file_path):
124
+ size_in_bytes = os.path.getsize(file_path)
125
+ size_in_megabytes = size_in_bytes / (1024 * 1024) # Convert bytes to megabytes
126
+
127
+ if size_in_megabytes > max_size_megabytes:
128
+ print("###################################")
129
+ print(f"Deleting s*** {filename} (Size: {size_in_megabytes:.2f} MB)")
130
+ os.remove(file_path)
131
+ print("###################################")
132
 
133
  def download_from_url(url):
134
  parent_path = find_folder_parent(".", "pretrained_v2")
135
  zips_path = os.path.join(parent_path, 'zips')
136
+ print(f"Limit download size in MB {os.getenv('MAX_DOWNLOAD_SIZE')}, duplicate the space for modify the limit")
137
 
138
  if url != '':
139
  print(i18n("Downloading the file: ") + f"{url}")
 
224
  os.chdir('./zips')
225
  wget.download(url)
226
 
227
+ #os.chdir('./zips')
228
+ delete_large_files(zips_path, int(os.getenv("MAX_DOWNLOAD_SIZE")))
229
  os.chdir(parent_path)
230
  print(i18n("Full download"))
231
  return "downloaded"