File size: 1,934 Bytes
102e49d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Startup script for Hugging Face Spaces deployment
Ensures spaCy model is available before starting the main app
"""

import subprocess
import sys
import os
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def install_spacy_model():
    """Install spaCy English model if not already available"""
    try:
        import spacy
        
        # Try to load the model
        try:
            nlp = spacy.load("en_core_web_sm")
            logger.info("βœ… spaCy model 'en_core_web_sm' is already available")
            return True
        except OSError:
            logger.info("πŸ“¦ spaCy model 'en_core_web_sm' not found, downloading...")
            
        # Download the model
        subprocess.check_call([
            sys.executable, "-m", "spacy", "download", "en_core_web_sm"
        ])
        
        # Verify installation
        nlp = spacy.load("en_core_web_sm")
        logger.info("βœ… spaCy model 'en_core_web_sm' downloaded and loaded successfully")
        return True
        
    except subprocess.CalledProcessError as e:
        logger.error(f"❌ Failed to download spaCy model: {e}")
        return False
    except Exception as e:
        logger.error(f"❌ Error setting up spaCy: {e}")
        return False

def main():
    """Main startup function"""
    logger.info("πŸš€ Starting TalentLens.AI...")
    
    # Install spaCy model
    model_success = install_spacy_model()
    
    if not model_success:
        logger.warning("⚠️ spaCy model not available, application will use fallback methods")
    
    # Import and run the main app
    try:
        from app import main as app_main
        logger.info("βœ… Starting Streamlit app...")
        app_main()
    except Exception as e:
        logger.error(f"❌ Failed to start main app: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()