Spaces:
Sleeping
Sleeping
File size: 1,936 Bytes
1bcc547 5a93d26 1bcc547 5a93d26 1bcc547 | 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 | # -*- 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() |