#!/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()