# -*- coding: utf-8 -*- """Clustering Use_model_cloud.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/19dFamN4Td92NqjpOmSrTE7L1kyiZtmTk """ import os import joblib """# **Web/API deployment** ## **Serialize the Model** """ saved_model_path = "files/prueba_clustering.joblib" os.path.getsize(saved_model_path) saved_model = joblib.load("files/prueba_clustering.joblib") saved_model """## **Write a Model Server**""" """### Define Function for Prediction""" import numpy as np def predict_cluster(RPM, Aceleración_LA, Velocidad_LA, Envolvente_LA, Aceleración_LI, Velocidad_LI, Envolvente_LI, Horas_Op): # Asume que el modelo necesita un array de numpy con una fila de features input_features = np.array([RPM, Aceleración_LA, Velocidad_LA, Envolvente_LA, Aceleración_LI, Velocidad_LI, Envolvente_LI, Horas_Op]).reshape(1, -1) cluster_number = saved_model.predict(input_features)[0] # Mapeo de número de cluster a nombre de cluster cluster_names = {0: "Operación Crítica", 1: "Operación Sub-óptima", 2: "Operación Normal"} cluster_name = cluster_names.get(cluster_number, "Cluster no identificado") return f"El cluster predicho es: {cluster_name}" """### Create Interface""" import gradio as gr iface = gr.Interface( fn=predict_cluster, inputs=[ gr.Number(label="RPM"), gr.Number(label="Aceleración_LA"), gr.Number(label="Velocidad_LA"), gr.Number(label="Envolvente_LA"), gr.Number(label="Aceleración_LI"), gr.Number(label="Velocidad_LI"), gr.Number(label="Envolvente_LI"), gr.Number(label="Horas_Op") ], outputs="text", title="Predicción de Condición de Operación del Activo", description="Introduce los valores de las características del motor para predecir la condición." ) # Lanzar la aplicación de Gradio iface.launch()