Sephfox commited on
Commit
2d3d752
·
verified ·
1 Parent(s): ba982a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -23,8 +23,27 @@ warnings.filterwarnings('ignore', category=FutureWarning, module='huggingface_hu
23
  nltk.download('vader_lexicon', quiet=True)
24
  nltk.download('punkt', quiet=True)
25
 
26
- # Load spaCy model
27
- nlp = spacy.load("en_core_web_sm")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # Initialize Example Dataset (For Emotion Prediction)
30
  data = {
 
23
  nltk.download('vader_lexicon', quiet=True)
24
  nltk.download('punkt', quiet=True)
25
 
26
+ ef download_spacy_model():
27
+ subprocess.check_call([sys.executable, "-m", "spacy", "download", "en_core_web_sm"])
28
+
29
+ try:
30
+ import spacy
31
+ try:
32
+ nlp = spacy.load("en_core_web_sm")
33
+ except OSError:
34
+ print("Downloading spaCy model...")
35
+ download_spacy_model()
36
+ nlp = spacy.load("en_core_web_sm")
37
+ except ImportError:
38
+ print("Error: Unable to import spaCy. NLP features will be disabled.")
39
+ nlp = None
40
+
41
+ def extract_entities(text):
42
+ if nlp is None:
43
+ return []
44
+ doc = nlp(text)
45
+ entities = [(ent.text, ent.label_) for ent in doc.ents]
46
+ return entities
47
 
48
  # Initialize Example Dataset (For Emotion Prediction)
49
  data = {