Spaces:
Sleeping
Sleeping
File size: 3,834 Bytes
5c2a9f0 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# SYSTEM CHECK MODULE
import os
import importlib
import sys
import logging
from pathlib import Path
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger('system_check')
def check_module_imports():
"""Check if all required modules can be imported"""
required_modules = [
"gradio", "numpy", "pandas", "matplotlib", "soundfile",
"scipy", "librosa", "plotly", "torch", "twilio", "pydub"
]
optional_modules = [
"fairseq", "pyworld", "parselmouth", "onnxruntime",
"transformers", "tqdm", "requests", "cachetools"
]
results = {
"required": {},
"optional": {},
"all_required_available": True
}
# Check required modules
for module_name in required_modules:
try:
importlib.import_module(module_name)
results["required"][module_name] = True
logger.info(f"β
Required module available: {module_name}")
except ImportError:
results["required"][module_name] = False
results["all_required_available"] = False
logger.error(f"β Required module {module_name} not available!")
# Check optional modules
for module_name in optional_modules:
try:
importlib.import_module(module_name)
results["optional"][module_name] = True
logger.info(f"β
Optional module available: {module_name}")
except ImportError:
results["optional"][module_name] = False
logger.warning(f"β οΈ Optional module {module_name} not available.")
return results
def check_file_permissions():
"""Check if required directories are writable"""
# Import here to avoid circular imports
try:
from modules.utils import DATA_DIR, CONFIG_DIR, LOGS_DIR
dirs_to_check = [DATA_DIR, CONFIG_DIR, LOGS_DIR]
results = {}
for directory in dirs_to_check:
# Create directory if it doesn't exist
os.makedirs(directory, exist_ok=True)
readable = os.access(directory, os.R_OK)
writable = os.access(directory, os.W_OK)
results[directory] = {
"exists": os.path.exists(directory),
"readable": readable,
"writable": writable
}
if not os.path.exists(directory):
logger.warning(f"β οΈ Directory doesn't exist: {directory}")
elif not writable:
logger.error(f"β Directory not writable: {directory}")
else:
logger.info(f"β
Directory writable: {directory}")
except ImportError:
logger.error("β Could not import directory paths from utils module")
results = {"error": "Could not import paths"}
return results
def run_system_check():
"""Run all system checks"""
logger.info("π Running system checks...")
results = {
"modules": check_module_imports(),
"environment": {
"is_huggingface": os.environ.get('SPACE_ID') is not None,
"python_version": sys.version,
"working_directory": os.getcwd()
}
}
# Only check file permissions after we've verified modules
if results["modules"]["all_required_available"]:
results["permissions"] = check_file_permissions()
# Log environment info
logger.info(f"Environment: {'Hugging Face' if results['environment']['is_huggingface'] else 'Local'}")
logger.info(f"Python version: {results['environment']['python_version']}")
logger.info(f"Working directory: {results['environment']['working_directory']}")
return results |