Spaces:
Runtime error
Runtime error
Update app.py
Browse files9 unmodified lines101112131415161713 unmodified lines3132333435363715 unmodified lines5354555657585960616263646566671 unmodified line69707172737475767778798081828325 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113223 unmodified lines1561571581591601611621639 unmodified lines# =========================================================app = FastAPI(title="NeuroHealth EEG System",version="8.0")DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")13 unmodified linesfeatures: list# =========================================================# AD MODEL (CNN - MUST MATCH TRAINING)# =========================================================class EEG_CNN_AD(nn.Module):15 unmodified linesdef forward(self, x):x = x.view(x.size(0), 19, 76)x = torch.relu(self.bn1(self.conv1(x)))x = torch.relu(self.bn2(self.conv2(x)))x = torch.relu(self.bn3(self.conv3(x)))x = self.pool(x).squeeze(-1)return self.fc(x)# =========================================================# PD MODEL (EXACT MATCH TO CHECKPOINT)# =========================================================class EEG_PD(nn.Module):1 unmodified linesuper().__init__()self.net = nn.Sequential(nn.Linear(76, 256),nn.ReLU(),nn.BatchNorm1d(256),nn.Linear(256, 128),nn.ReLU(),nn.BatchNorm1d(128),nn.Linear(128, 2))def forward(self, x):25 unmodified linesprint("System ready")# =========================================================# INPUT HANDLER# =========================================================def prepare(features, model_type):x = torch.tensor(features, dtype=torch.float32)if model_type == "ad":return x.view(1, 19, 76)elif model_type == "pd":return x.view(1, 76)else:raise ValueError("Invalid model type")# =========================================================# PREDICT ENGINE# =========================================================def predict(model, features, classes, model_type):23 unmodified linesreturn {"status": "running","ad_input": "19x76 CNN","pd_input": "76 Dense","version": "8.0"}@app.get("/health")9 unmodified lines101112131415161713 unmodified lines3132333435363715 unmodified lines53545556575859606162636465666768697071721 unmodified line747576777879808182838485868788899025 unmodified lines11611711811912012112212312412512612712812913013113213313413513613723 unmodified lines1611621631641651661671689 unmodified lines# =========================================================app = FastAPI(title="NeuroHealth EEG API",version="9.0")DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")13 unmodified linesfeatures: list# =========================================================# AD MODEL (CNN - EXACTLY FROM CHECKPOINT STRUCTURE)# =========================================================class EEG_CNN_AD(nn.Module):15 unmodified linesdef forward(self, x):x = x.view(x.size(0), 19, 76)x = torch.relu(self.conv1(x))x = self.bn1(x)x = torch.relu(self.conv2(x))x = self.bn2(x)x = torch.relu(self.conv3(x))x = self.bn3(x)x = self.pool(x).squeeze(-1)return self.fc(x)# =========================================================# PD MODEL (STRICT MATCH TO YOUR CHECKPOINT KEYS)# =========================================================class EEG_PD(nn.Module):1 unmodified linesuper().__init__()self.net = nn.Sequential(nn.Linear(76, 256), # net.0nn.ReLU(),nn.BatchNorm1d(256), # net.2nn.Linear(256, 128), # net.4nn.ReLU(),nn.BatchNorm1d(128), # net.6nn.Linear(128, 2) # net.7)def forward(self, x):25 unmodified linesprint("System ready")# =========================================================# PREPROCESSING# =========================================================def prepare(features, model_type):x = torch.tensor(features, dtype=torch.float32)if model_type == "ad":return x.view(1, 19, 76)if model_type == "pd":return x.view(1, 76)raise ValueError("Invalid model type")# =========================================================# PREDICTION ENGINE# =========================================================def predict(model, features, classes, model_type):23 unmodified linesreturn {"status": "running","ad_input": "19x76 CNN","pd_input": "76 features MLP","version": "9.0"}@app.get("/health")
app.py+25-20