File size: 3,071 Bytes
4a8b134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Application Configuration
"""
import os
from typing import Optional
import logging

logger = logging.getLogger(__name__)

def _detect_gpu():
    """Detect if GPU/CUDA is available"""
    try:
        import torch
        return torch.cuda.is_available()
    except (ImportError, Exception):
        return False

def _get_max_drugs(use_gpu: bool) -> int:
    """Get max drugs based on GPU availability"""
    if use_gpu:
        return 600  # GPU can handle more drugs
    else:
        return 200  # CPU limited for performance

class Settings:
    """Application settings"""
    
    # Application Info
    APP_NAME: str = "Drug Repurposing AI System"
    APP_VERSION: str = "1.0.0"
    APP_DESCRIPTION: str = "AI-powered drug repurposing system using Deep Learning and Open Targets"
    
    # API Configuration
    API_TITLE: str = "Drug Repurposing API"
    API_VERSION: str = "v1"
    DEBUG: bool = os.getenv("DEBUG", "False").lower() == "true"
    
    # Server Configuration
    HOST: str = os.getenv("HOST", "0.0.0.0")
    PORT: int = int(os.getenv("PORT", "8000"))
    
    # API Keys and URLs
    OPENTARGETS_API_URL: str = "https://api.platform.opentargets.org/api/v4/graphql"
    UNIPROT_API_URL: str = "https://rest.uniprot.org/uniprotkb/search"
    
    # GPU Detection
    HAS_GPU: bool = _detect_gpu()
    DEVICE: str = "cuda" if HAS_GPU else "cpu"
    
    # Model Configuration
    DEEP_PURPOSE_MODEL: str = os.getenv("DEEP_PURPOSE_MODEL", "MPNN_CNN_BindingDB")
    USE_MOCK_MODEL: bool = os.getenv("USE_MOCK_MODEL", "False").lower() == "true"  # PRODUCTION: Always False
    USE_MOCK_DRUGS: bool = os.getenv("USE_MOCK_DRUGS", "False").lower() == "true"  # PRODUCTION: Always False
    
    # Screening Parameters
    DEFAULT_TOP_TARGETS: int = 10
    DEFAULT_TOP_RESULTS: int = 15
    DEFAULT_MIN_SCORE: float = 0.0
    MAX_TARGETS: int = 50
    MAX_DRUGS_FOR_DEMO: int = _get_max_drugs(HAS_GPU)
    BATCH_SIZE: int = 32 if HAS_GPU else 8  # Batch size for predictions
    
    # TDC Configuration
    TDC_DATASET: str = os.getenv("TDC_DATASET", "Half_Life_Obach")
    TDC_TIMEOUT: int = 300  # Timeout for TDC downloads in seconds
    
    # Logging Configuration
    LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
    LOG_FORMAT: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    
    # CORS Configuration
    CORS_ORIGINS: list = ["*"]
    CORS_CREDENTIALS: bool = True
    CORS_METHODS: list = ["*"]
    CORS_HEADERS: list = ["*"]
    
    # Timeout Settings
    API_TIMEOUT: int = 60
    REQUEST_TIMEOUT: int = 300
    
    # Production Mode
    PRODUCTION_MODE: bool = os.getenv("PRODUCTION_MODE", "False").lower() == "true"

    @classmethod
    def get_settings(cls) -> 'Settings':
        """Get application settings instance"""
        return cls()


settings = Settings.get_settings()

# Log GPU status on startup
if settings.HAS_GPU:
    logger.info(f"✅ GPU/CUDA detected. Max drugs: {settings.MAX_DRUGS_FOR_DEMO}")
else:
    logger.info(f"⚠️ No GPU detected. CPU mode. Max drugs: {settings.MAX_DRUGS_FOR_DEMO}")