Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines789101112133 unmodified lines17181920212223242526272829303119 unmodified lines515253545556576 unmodified linesfrom huggingface_hub import hf_hub_download# --- Descarga y carga de modelos SVM en runtime ---# Ajusta repo_id si es privado y añade HF_TOKEN en Secrets.svm_path = hf_hub_download(repo_id="Calotriton/RibbID_SVM", filename="svm_mfcc_model.joblib")3 unmodified linessvm = joblib.load(svm_path)scaler = joblib.load(scaler_path)# --- Descarga y carga de modelo CNN en runtime ---cnn_path = hf_hub_download(repo_id="Calotriton/RibbID_CNN", filename="CNN_final.pth")encoder_path = hf_hub_download(repo_id="Calotriton/RibbID_CNN", filename="label_encoder_and_thresholds.pkl")cnn = torch.load(cnn_path, map_location=torch.device('cpu'))cnn.eval()with open(encoder_path, "rb") as f:data = pickle.load(f)LABELS = data.get("labels")19 unmodified lineswith torch.no_grad():probs = torch.sigmoid(cnn(x)).numpy().flatten()# Selección de umbral (dict o slider genérico)if isinstance(THRESHOLDS, dict):thr = np.array([THRESHOLDS.get(lbl, 0.5) for lbl in LABELS])else:6 unmodified lines7891011123 unmodified lines1617181920212223242526272829303132333435363719 unmodified lines5758596061626 unmodified linesfrom huggingface_hub import hf_hub_download# --- Descarga y carga de modelos SVM en runtime ---svm_path = hf_hub_download(repo_id="Calotriton/RibbID_SVM", filename="svm_mfcc_model.joblib")3 unmodified linessvm = joblib.load(svm_path)scaler = joblib.load(scaler_path)# --- Definición de la arquitectura CNN ---# Importa o define aquí la clase de tu modelo CNN, p.ej. `class MyCNN(nn.Module): ...`from model import MyCNN# --- Descarga y carga de modelo CNN en runtime ---cnn_state = hf_hub_download(repo_id="Calotriton/RibbID_CNN", filename="CNN_final.pth")# Crea instancia y carga pesoscnn = MyCNN()cnn.load_state_dict(torch.load(cnn_state, map_location=torch.device('cpu')))cnn.eval()encoder_path = hf_hub_download(repo_id="Calotriton/RibbID_CNN", filename="label_encoder_and_thresholds.pkl")with open(encoder_path, "rb") as f:data = pickle.load(f)LABELS = data.get("labels")19 unmodified lineswith torch.no_grad():probs = torch.sigmoid(cnn(x)).numpy().flatten()if isinstance(THRESHOLDS, dict):thr = np.array([THRESHOLDS.get(lbl, 0.5) for lbl in LABELS])else:
app.py+10-5