Spaces:
Sleeping
Sleeping
Bugfix.
Browse files- install_packages.py +57 -0
- requirements.txt +2 -1
install_packages.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def download_model(url, save_path):
|
| 9 |
+
# Send a GET request to the URL
|
| 10 |
+
response = requests.get(url, stream=True)
|
| 11 |
+
|
| 12 |
+
# Check if the request was successful (status code 200)
|
| 13 |
+
if response.status_code == 200:
|
| 14 |
+
# Open a file in binary write mode to save the downloaded content
|
| 15 |
+
with open(save_path, 'wb') as f:
|
| 16 |
+
# Iterate over the response content in chunks and write to the file
|
| 17 |
+
for chunk in response.iter_content(chunk_size=1024):
|
| 18 |
+
f.write(chunk)
|
| 19 |
+
print("Model downloaded successfully!")
|
| 20 |
+
else:
|
| 21 |
+
# Print an error message if the request was not successful
|
| 22 |
+
print(f"Failed to download model. Status code: {response.status_code}")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def set_tokenizers_parallelism(value):
|
| 26 |
+
"""Set the TOKENIZERS_PARALLELISM environment variable."""
|
| 27 |
+
os.environ['TOKENIZERS_PARALLELISM'] = 'true' if value else 'false'
|
| 28 |
+
print(f"TOKENIZERS_PARALLELISM set to {os.environ['TOKENIZERS_PARALLELISM']}")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def install_requirements():
|
| 32 |
+
"""Install packages listed in requirements.txt"""
|
| 33 |
+
try:
|
| 34 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
|
| 35 |
+
print("All packages from requirements.txt installed successfully.")
|
| 36 |
+
except subprocess.CalledProcessError as e:
|
| 37 |
+
print(f"Failed to install packages from requirements.txt: {e}")
|
| 38 |
+
sys.exit(1)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def install_spacy_model(model_name):
|
| 42 |
+
"""Install a specific spaCy model"""
|
| 43 |
+
try:
|
| 44 |
+
subprocess.check_call([sys.executable, "-m", "spacy", "download", model_name])
|
| 45 |
+
print(f"spaCy model '{model_name}' installed successfully.")
|
| 46 |
+
except subprocess.CalledProcessError as e:
|
| 47 |
+
print(f"Failed to install spaCy model '{model_name}': {e}")
|
| 48 |
+
sys.exit(1)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
install_requirements()
|
| 53 |
+
install_spacy_model("de_core_news_lg")
|
| 54 |
+
install_spacy_model("fr_core_news_lg")
|
| 55 |
+
install_spacy_model("it_core_news_lg")
|
| 56 |
+
set_tokenizers_parallelism(True)
|
| 57 |
+
download_model('https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin', 'lid.176.bin')
|
requirements.txt
CHANGED
|
@@ -17,4 +17,5 @@ swissparlpy==0.3.0
|
|
| 17 |
tqdm==4.66.1
|
| 18 |
transformers==4.39.3
|
| 19 |
spacy==3.7.4
|
| 20 |
-
huggingface_hub
|
|
|
|
|
|
| 17 |
tqdm==4.66.1
|
| 18 |
transformers==4.39.3
|
| 19 |
spacy==3.7.4
|
| 20 |
+
huggingface_hub
|
| 21 |
+
requests
|