Shujaat Ali commited on
Commit
7c9a059
·
verified ·
1 Parent(s): 23a08cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -5,13 +5,18 @@ import torch
5
  import nltk
6
  import spacy
7
  from nltk.corpus import wordnet
 
8
 
9
  # Download NLTK data (if not already downloaded)
10
  nltk.download('punkt')
11
  nltk.download('stopwords')
12
 
13
- # Load spaCy model for English
14
- nlp = spacy.load("en_core_web_sm")
 
 
 
 
15
 
16
  # Check for GPU and set the device accordingly
17
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
5
  import nltk
6
  import spacy
7
  from nltk.corpus import wordnet
8
+ import subprocess
9
 
10
  # Download NLTK data (if not already downloaded)
11
  nltk.download('punkt')
12
  nltk.download('stopwords')
13
 
14
+ # Download spaCy model if not already installed
15
+ try:
16
+ nlp = spacy.load("en_core_web_sm")
17
+ except OSError:
18
+ subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
19
+ nlp = spacy.load("en_core_web_sm")
20
 
21
  # Check for GPU and set the device accordingly
22
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")