Update app.py
Browse files
app.py
CHANGED
|
@@ -24,24 +24,16 @@ ARCHIVE_PATH = f"./transformers_{TRANSFORMERS_REPOSITORY_REVISION}.tar.gz"
|
|
| 24 |
HF_BASE_URL = "https://huggingface.co"
|
| 25 |
|
| 26 |
if not os.path.exists(TRANSFORMERS_REPOSITORY_PATH):
|
| 27 |
-
# Download the .tar.gz file
|
| 28 |
-
print(f"Downloading the repository from {TRANSFORMERS_REPOSITORY_URL}...")
|
| 29 |
urllib.request.urlretrieve(TRANSFORMERS_REPOSITORY_URL, ARCHIVE_PATH)
|
| 30 |
|
| 31 |
-
# Create a temporary directory for extraction
|
| 32 |
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 33 |
-
# Extract the .tar.gz file to temp directory
|
| 34 |
-
print(f"Extracting the archive {ARCHIVE_PATH}...")
|
| 35 |
with tarfile.open(ARCHIVE_PATH, "r:gz") as tar:
|
| 36 |
tar.extractall(tmp_dir)
|
| 37 |
|
| 38 |
-
# Get the extracted folder name (there should be only one)
|
| 39 |
extracted_folder = os.path.join(tmp_dir, os.listdir(tmp_dir)[0])
|
| 40 |
|
| 41 |
-
# Move to final destination
|
| 42 |
os.rename(extracted_folder, TRANSFORMERS_REPOSITORY_PATH)
|
| 43 |
|
| 44 |
-
# Remove the downloaded .tar.gz archive
|
| 45 |
os.remove(ARCHIVE_PATH)
|
| 46 |
print("Repository downloaded and extracted successfully.")
|
| 47 |
|
|
|
|
| 24 |
HF_BASE_URL = "https://huggingface.co"
|
| 25 |
|
| 26 |
if not os.path.exists(TRANSFORMERS_REPOSITORY_PATH):
|
|
|
|
|
|
|
| 27 |
urllib.request.urlretrieve(TRANSFORMERS_REPOSITORY_URL, ARCHIVE_PATH)
|
| 28 |
|
|
|
|
| 29 |
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
|
|
|
|
|
| 30 |
with tarfile.open(ARCHIVE_PATH, "r:gz") as tar:
|
| 31 |
tar.extractall(tmp_dir)
|
| 32 |
|
|
|
|
| 33 |
extracted_folder = os.path.join(tmp_dir, os.listdir(tmp_dir)[0])
|
| 34 |
|
|
|
|
| 35 |
os.rename(extracted_folder, TRANSFORMERS_REPOSITORY_PATH)
|
| 36 |
|
|
|
|
| 37 |
os.remove(ARCHIVE_PATH)
|
| 38 |
print("Repository downloaded and extracted successfully.")
|
| 39 |
|