Rogaton
Claude
commited on
Commit
·
cc8e202
1
Parent(s):
eee0fe0
fix: Auto-download Stanza Coptic models on first use
Browse files- Modified CopticParserCore.load_parser() to detect missing models
- Automatically downloads Coptic models via stanza.download('cop')
- Added detailed error handling and user feedback
- Modified get_parser() to load models on-demand, not at initialization
- Fixes "Resources file not found" error in HuggingFace deployment
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
- apertus_ui.py +2 -1
- coptic_parser_core.py +32 -9
apertus_ui.py
CHANGED
|
@@ -313,7 +313,8 @@ def get_parser():
|
|
| 313 |
"""Initialize and cache the Coptic parser"""
|
| 314 |
try:
|
| 315 |
parser = CopticParserCore()
|
| 316 |
-
|
|
|
|
| 317 |
return parser
|
| 318 |
except Exception as e:
|
| 319 |
st.error(f"Failed to initialize parser: {e}")
|
|
|
|
| 313 |
"""Initialize and cache the Coptic parser"""
|
| 314 |
try:
|
| 315 |
parser = CopticParserCore()
|
| 316 |
+
# Note: Don't pre-load here, load on demand to avoid startup delays
|
| 317 |
+
# First use will trigger model download if needed
|
| 318 |
return parser
|
| 319 |
except Exception as e:
|
| 320 |
st.error(f"Failed to initialize parser: {e}")
|
coptic_parser_core.py
CHANGED
|
@@ -25,15 +25,38 @@ class CopticParserCore:
|
|
| 25 |
|
| 26 |
print("Loading Coptic NLP models...")
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def parse_text(self, text):
|
| 39 |
"""
|
|
|
|
| 25 |
|
| 26 |
print("Loading Coptic NLP models...")
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
# Try to load Stanza with all processors
|
| 30 |
+
self.nlp = stanza.Pipeline(
|
| 31 |
+
lang='cop',
|
| 32 |
+
processors='tokenize,pos,lemma,depparse',
|
| 33 |
+
download_method=None,
|
| 34 |
+
verbose=False
|
| 35 |
+
)
|
| 36 |
+
print("✓ Coptic parser loaded successfully")
|
| 37 |
+
|
| 38 |
+
except Exception as e:
|
| 39 |
+
# If models not found, download them
|
| 40 |
+
if "Resources file not found" in str(e) or "not found" in str(e).lower():
|
| 41 |
+
print("📥 Coptic models not found. Downloading (this may take 2-3 minutes)...")
|
| 42 |
+
try:
|
| 43 |
+
# Download Coptic models
|
| 44 |
+
stanza.download('cop', verbose=False)
|
| 45 |
+
|
| 46 |
+
# Try loading again
|
| 47 |
+
self.nlp = stanza.Pipeline(
|
| 48 |
+
lang='cop',
|
| 49 |
+
processors='tokenize,pos,lemma,depparse',
|
| 50 |
+
download_method=None,
|
| 51 |
+
verbose=False
|
| 52 |
+
)
|
| 53 |
+
print("✓ Coptic models downloaded and loaded successfully")
|
| 54 |
+
except Exception as download_error:
|
| 55 |
+
print(f"❌ Failed to download Coptic models: {download_error}")
|
| 56 |
+
raise
|
| 57 |
+
else:
|
| 58 |
+
print(f"❌ Failed to load parser: {e}")
|
| 59 |
+
raise
|
| 60 |
|
| 61 |
def parse_text(self, text):
|
| 62 |
"""
|