Update nylon.py
Browse files
nylon.py
CHANGED
@@ -21,10 +21,31 @@ except AttributeError:
|
|
21 |
else:
|
22 |
ssl._create_default_https_context = _create_unverified_https_context
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
nltk.download('stopwords')
|
25 |
nltk.download('punkt')
|
26 |
|
27 |
-
nlp = spacy.load('en_core_web_sm')
|
28 |
q = 0
|
29 |
|
30 |
def get_keywords(text, cache):
|
|
|
21 |
else:
|
22 |
ssl._create_default_https_context = _create_unverified_https_context
|
23 |
|
24 |
+
|
25 |
+
import sys
|
26 |
+
import subprocess
|
27 |
+
|
28 |
+
def download_spacy_model(model_name):
|
29 |
+
print(f"Downloading spaCy model: {model_name}")
|
30 |
+
subprocess.check_call([sys.executable, "-m", "spacy", "download", model_name])
|
31 |
+
print(f"Model {model_name} downloaded successfully")
|
32 |
+
|
33 |
+
# Usage
|
34 |
+
try:
|
35 |
+
nlp = spacy.load('en_core_web_sm')
|
36 |
+
except OSError:
|
37 |
+
# If the model is not found, download it
|
38 |
+
download_spacy_model('en_core_web_sm')
|
39 |
+
# Try loading again
|
40 |
+
import spacy
|
41 |
+
nlp = spacy.load('en_core_web_sm')
|
42 |
+
|
43 |
+
# Now you can use the model
|
44 |
+
print("spaCy model loaded successfully")
|
45 |
+
|
46 |
nltk.download('stopwords')
|
47 |
nltk.download('punkt')
|
48 |
|
|
|
49 |
q = 0
|
50 |
|
51 |
def get_keywords(text, cache):
|