Spaces:
Runtime error
Runtime error
Download verify_deployment.py from kalyan9/HealthGuard-AI: direct link, hf CLI and curl.
- Browser
- Download file 6.91 kB
-
https://huggingface.co/spaces/kalyan9/HealthGuard-AI/resolve/main/verify_deployment.py
- Command line
-
hf download hf://spaces/kalyan9/HealthGuard-AI/verify_deployment.py
-
curl -L -o verify_deployment.py https://huggingface.co/spaces/kalyan9/HealthGuard-AI/resolve/main/verify_deployment.py
6.91 kB
| """ | |
| Verification script for HealthGuard-AI deployment. | |
| This script checks if all components are working correctly. | |
| """ | |
| import os | |
| import sys | |
| import importlib | |
| from datetime import datetime | |
| def check_python_version(): | |
| """Check if Python version is compatible.""" | |
| print("=== Python Version Check ===") | |
| version = sys.version | |
| print(f"Python version: {version}") | |
| # Check if it's Python 3.7 or higher | |
| if sys.version_info >= (3, 7): | |
| print("β Python version is compatible") | |
| return True | |
| else: | |
| print("β Python version is not compatible (requires 3.7+)") | |
| return False | |
| def check_environment_variables(): | |
| """Check if required environment variables are set.""" | |
| print("\n=== Environment Variables Check ===") | |
| required_vars = ['MONGODB_URI'] | |
| optional_vars = ['SECRET_KEY', 'MONGODB_DB'] | |
| for var in required_vars: | |
| value = os.getenv(var) | |
| if value: | |
| print(f"β {var}: Set") | |
| else: | |
| print(f"β {var}: Not set (REQUIRED)") | |
| for var in optional_vars: | |
| value = os.getenv(var) | |
| if value: | |
| print(f"β {var}: Set") | |
| else: | |
| print(f"β {var}: Not set (optional)") | |
| return all(os.getenv(var) for var in required_vars) | |
| def check_required_packages(): | |
| """Check if all required packages are installed.""" | |
| print("\n=== Required Packages Check ===") | |
| required_packages = [ | |
| 'flask', | |
| 'pymongo', | |
| 'bcrypt', | |
| 'pandas', | |
| 'reportlab', | |
| 'flask_pymongo', | |
| 'flask_session', | |
| 'python-dotenv', | |
| 'certifi' | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| importlib.import_module(package) | |
| print(f"β {package}: Installed") | |
| except ImportError: | |
| print(f"β {package}: Not installed") | |
| missing_packages.append(package) | |
| if missing_packages: | |
| print(f"\nMissing packages: {', '.join(missing_packages)}") | |
| print("Install them with: pip install " + " ".join(missing_packages)) | |
| return False | |
| else: | |
| print("β All required packages are installed") | |
| return True | |
| def check_file_structure(): | |
| """Check if required files and directories exist.""" | |
| print("\n=== File Structure Check ===") | |
| required_files = [ | |
| 'app.py', | |
| 'requirements.txt', | |
| 'debug_routes.py', | |
| 'logging_config.py' | |
| ] | |
| required_dirs = [ | |
| 'templates', | |
| 'static', | |
| 'saved models' | |
| ] | |
| missing_files = [] | |
| missing_dirs = [] | |
| for file in required_files: | |
| if os.path.isfile(file): | |
| print(f"β {file}: Exists") | |
| else: | |
| print(f"β {file}: Missing") | |
| missing_files.append(file) | |
| for directory in required_dirs: | |
| if os.path.isdir(directory): | |
| print(f"β {directory}: Exists") | |
| else: | |
| print(f"β {directory}: Missing") | |
| missing_dirs.append(directory) | |
| if missing_files or missing_dirs: | |
| print(f"\nMissing items: {', '.join(missing_files + missing_dirs)}") | |
| return False | |
| else: | |
| print("β All required files and directories exist") | |
| return True | |
| def check_model_files(): | |
| """Check if model files exist.""" | |
| print("\n=== Model Files Check ===") | |
| model_dir = 'saved models' | |
| required_models = [ | |
| 'diabetes_model.sav', | |
| 'heart_disease_model.sav', | |
| 'parkinsons_model.sav' | |
| ] | |
| if not os.path.isdir(model_dir): | |
| print(f"β {model_dir}: Directory not found") | |
| return False | |
| missing_models = [] | |
| for model in required_models: | |
| model_path = os.path.join(model_dir, model) | |
| if os.path.isfile(model_path): | |
| print(f"β {model}: Exists") | |
| else: | |
| print(f"β {model}: Missing") | |
| missing_models.append(model) | |
| if missing_models: | |
| print(f"\nMissing models: {', '.join(missing_models)}") | |
| return False | |
| else: | |
| print("β All model files exist") | |
| return True | |
| def check_template_files(): | |
| """Check if template files exist.""" | |
| print("\n=== Template Files Check ===") | |
| template_dir = 'templates' | |
| required_templates = [ | |
| 'index.html', | |
| 'auth/login.html', | |
| 'auth/register.html', | |
| 'user/dashboard.html' | |
| ] | |
| if not os.path.isdir(template_dir): | |
| print(f"β {template_dir}: Directory not found") | |
| return False | |
| missing_templates = [] | |
| for template in required_templates: | |
| template_path = os.path.join(template_dir, template) | |
| if os.path.isfile(template_path): | |
| print(f"β {template}: Exists") | |
| else: | |
| # Check in subdirectories | |
| found = False | |
| for root, dirs, files in os.walk(template_dir): | |
| if template in files: | |
| print(f"β {template}: Exists (in {root})") | |
| found = True | |
| break | |
| if not found: | |
| print(f"β {template}: Missing") | |
| missing_templates.append(template) | |
| if missing_templates: | |
| print(f"\nMissing templates: {', '.join(missing_templates)}") | |
| return False | |
| else: | |
| print("β All required template files exist") | |
| return True | |
| def main(): | |
| """Main verification function.""" | |
| print("HealthGuard-AI Deployment Verification") | |
| print("=" * 40) | |
| print(f"Time: {datetime.now()}") | |
| print(f"Working directory: {os.getcwd()}") | |
| print() | |
| checks = [ | |
| check_python_version, | |
| check_environment_variables, | |
| check_required_packages, | |
| check_file_structure, | |
| check_model_files, | |
| check_template_files | |
| ] | |
| results = [] | |
| for check in checks: | |
| try: | |
| result = check() | |
| results.append(result) | |
| print() | |
| except Exception as e: | |
| print(f"Error during {check.__name__}: {e}") | |
| results.append(False) | |
| print() | |
| # Summary | |
| print("=" * 40) | |
| print("Verification Summary:") | |
| passed = sum(results) | |
| total = len(results) | |
| print(f"Checks passed: {passed}/{total}") | |
| if all(results): | |
| print("β All checks passed! Deployment should work correctly.") | |
| return True | |
| else: | |
| print("β Some checks failed. Please fix the issues before deployment.") | |
| return False | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) |