ls_be_T5_base / _wsgi.py
b2u's picture
fixing CUDA issue
a9b8d74
import os
import logging
import logging.config
from pathlib import Path
from dotenv import load_dotenv
import datetime
import multiprocessing
# Set multiprocessing start method to 'spawn'
multiprocessing.set_start_method('spawn', force=True)
from label_studio_ml.api import init_app
from model import T5Model
# Load environment variables from .env file if it exists
load_dotenv()
# Configure logging
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '[%(asctime)s] [%(levelname)s] [%(name)s::%(funcName)s::%(lineno)d] %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': os.getenv('LOG_LEVEL', 'DEBUG'),
'stream': 'ext://sys.stdout',
'formatter': 'standard'
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': os.getenv('LOG_LEVEL', 'DEBUG'),
'propagate': True
},
'model': {
'handlers': ['console'],
'level': os.getenv('LOG_LEVEL', 'DEBUG'),
'propagate': False
}
}
})
logger = logging.getLogger(__name__)
# Initialize the app at module level for Gunicorn
app = init_app(
model_class=T5Model,
basic_auth_user=os.environ.get('BASIC_AUTH_USER'),
basic_auth_pass=os.environ.get('BASIC_AUTH_PASS'),
)
logger.info("===== Application Startup at %s =====", datetime.datetime.now())
logger.info("Model class: %s", T5Model.__name__)
logger.info("Environment variables:")
for key, value in os.environ.items():
if not key.startswith(('PATH', 'PYTHON', 'HOME')): # Skip system variables
logger.info(" %s: %s", key, value)
if __name__ == "__main__":
# Run the app when executed directly
app.run(
host='0.0.0.0',
port=int(os.environ.get('PORT', 9090)),
debug=os.environ.get('DEBUG', 'False').lower() == 'true'
)