File size: 2,280 Bytes
5feba25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from pathlib import Path
from dotenv import load_dotenv

# Load environment
load_dotenv()

# Paths - robust for both local and HF Spaces deployment
BASE_DIR = Path(__file__).parent.parent

# Try multiple possible model locations
_possible_paths = [
    BASE_DIR / "models" / "GradientBoosting_model.pkl",  # Local development
    BASE_DIR / "model" / "GradientBoosting_model.pkl",   # If named 'model' instead
    Path("/app/models/GradientBoosting_model.pkl"),      # HF Spaces absolute path
    Path.cwd() / "models" / "GradientBoosting_model.pkl", # Current working directory
]

MODEL_PATH = None
for path in _possible_paths:
    if path.exists():
        MODEL_PATH = path
        break

# Default to first path if none found (will error gracefully)
if MODEL_PATH is None:
    MODEL_PATH = _possible_paths[0]

# Groq API configuration
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
GROQ_MODEL = "llama-3.1-70b-versatile"
GROQ_TEMPERATURE = 0
GROQ_TIMEOUT = 30

# Medical features (all 16)
DEFAULT_MODEL_FEATURES = [
    "LengthOfStay",
    "Smoking",
    "Family History",
    "HbA1c",
    "Glucose",
    "Age",
    "Diet Score",
    "Alcohol",
    "Physical Activity",
    "Blood Pressure",
    "BMI",
    "Cholesterol",
    "Sleep Hours",
    "Stress Level",
    "Triglycerides",
    "Oxygen Saturation"
]

# Feature validation ranges (min, max, expected type)
FEATURE_RANGES = {
    "Age": (0, 150, float),
    "Glucose": (70, 400, float),
    "HbA1c": (3, 15, float),
    "BMI": (10, 60, float),
    "Cholesterol": (100, 400, float),
    "Triglycerides": (20, 500, float),
    "Blood Pressure": (60, 200, float),
    "Physical Activity": (0, 24, float),
    "Sleep Hours": (0, 24, float),
    "Stress Level": (1, 10, float),
    "Diet Score": (1, 10, float),
    "Smoking": (0, 1, int),
    "Alcohol": (0, 1, int),
    "Family History": (0, 1, int),
    "LengthOfStay": (0, 365, int),
    "Oxygen Saturation": (80, 100, float),
}

# Model configuration
MIN_FEATURES_FOR_PREDICTION = 16  # Ask for all 16 features
MAX_RETRIES = 3

# Prediction classes
CLASS_NAMES = [
    "Arthritis",
    "Asthma",
    "Cancer",
    "Diabetes",
    "Healthy",
    "Hypertension",
    "Obesity",
    "Other/Unknown",
]

# App configuration
DEBUG_MODE = True
CONVERSATION_MAX_TURNS = 20