Pradeep Kumar commited on
Commit
0d30233
·
verified ·
1 Parent(s): 3bccb0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -2,21 +2,22 @@ import zipfile
2
  import sys
3
  import os
4
 
5
- # Paths to the ZIP file and the extraction directory
6
- zip_file_path = '/home/user/app/models.zip'
7
- extract_dir = '/home/user/app/models/'
8
-
9
- # Ensure the extraction directory exists (create it if it doesn't)
10
- if not os.path.exists(extract_dir):
11
- os.makedirs(extract_dir)
12
-
13
- # Unzipping the file
14
- try:
15
- with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
16
- zip_ref.extractall(extract_dir)
17
- print(f"Files in '{extract_dir}' directory:", os.listdir(extract_dir))
18
- except Exception as e:
19
- print(f"An error occurred: {e}")
 
20
 
21
  # Check current directory and list files
22
  print("Current Directory:", os.getcwd())
 
2
  import sys
3
  import os
4
 
5
+
6
+ def unzip_file(zip_path, extract_to=None):
7
+ # Check if extract_to is provided, otherwise extract in the current directory
8
+ if extract_to is None:
9
+ extract_to = os.path.dirname(zip_path) # Extract in the same directory as the zip file
10
+
11
+ # Open the zip file
12
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
13
+ # Extract all the contents into the extract_to directory
14
+ zip_ref.extractall(extract_to)
15
+ print(f"Extracted all files to {extract_to}")
16
+
17
+
18
+ zip_file_path = 'models.zip' # Replace with your zip file path
19
+ unzip_file(zip_file_path) # This will extract to the same directory as the zip file
20
+
21
 
22
  # Check current directory and list files
23
  print("Current Directory:", os.getcwd())