Bhavyajethi commited on
Commit
8701310
·
verified ·
1 Parent(s): 8a9e45b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -43,10 +43,21 @@ def analyze_sentiment(text):
43
 
44
  return sentiment
45
 
46
- # Load spaCy model
 
 
 
47
  @st.cache_resource
48
  def load_spacy_model():
49
- return spacy.load("en_core_web_sm")
 
 
 
 
 
 
 
 
50
 
51
  nlp = load_spacy_model()
52
 
 
43
 
44
  return sentiment
45
 
46
+ import spacy
47
+ import subprocess
48
+ import sys
49
+
50
  @st.cache_resource
51
  def load_spacy_model():
52
+ try:
53
+ # Attempt to load the model
54
+ nlp = spacy.load("en_core_web_sm")
55
+ except OSError:
56
+ # If the model isn't found, download it
57
+ st.info("Model 'en_core_web_sm' not found. Downloading now...")
58
+ subprocess.check_call([sys.executable, "-m", "spacy", "download", "en_core_web_sm"])
59
+ nlp = spacy.load("en_core_web_sm")
60
+ return nlp
61
 
62
  nlp = load_spacy_model()
63