Spaces:
Build error
Build error
Commit ·
454f21d
1
Parent(s): 23e4091
Fix NLTK data paths and tokenizer loading
Browse files5 unmodified lines6789101112131415162 unmodified lines192021222324255 unmodified linesclass DocumentSummarizer:def __init__(self):# NLTK 다운로드try:nltk.download('punkt', download_dir='/app/nltk_data')nltk.download('stopwords', download_dir='/app/nltk_data')nltk.data.path.append('/app/nltk_data')except Exception as e:print(f"Warning: NLTK data download failed: {str(e)}")2 unmodified linestry:self.tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')except Exception as e:print(f"Warning: Failed to load tokenizer: {str(e)}")self.tokenizer = nltk.tokenize.sent_tokenizedef summarize_text(self, text: str) -> Dict:5 unmodified lines678910111213141516171819202122232425262728293031322 unmodified lines35363738394041425 unmodified linesclass DocumentSummarizer:def __init__(self):# Set NLTK data pathnltk_data_paths = ['/usr/local/share/nltk_data','/usr/share/nltk_data','/usr/local/nltk_data','/usr/local/lib/nltk_data','/usr/lib/nltk_data','/root/nltk_data','/home/user/nltk_data','/app/nltk_data']# Add all possible NLTK data pathsnltk.data.path = list(dict.fromkeys(nltk_data_paths + nltk.data.path))# Download NLTK data if not foundtry:nltk.download('punkt')nltk.download('stopwords')nltk.download('wordnet')nltk.download('averaged_perceptron_tagger')except Exception as e:print(f"Warning: NLTK data download failed: {str(e)}")2 unmodified linestry:self.tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')except Exception as e:print(f"Warning: Failed to load punkt tokenizer: {str(e)}")# Fallback to default sent_tokenizeself.tokenizer = nltk.tokenize.sent_tokenizedef summarize_text(self, text: str) -> Dict:
summarizer.py+22-5