|
|
from huggingface_hub import from_pretrained_keras |
|
|
import gradio as gr |
|
|
import numpy as np |
|
|
import tensorflow as tf |
|
|
|
|
|
|
|
|
repo_id = "ramirces/anomalydetectiondataset" |
|
|
learner = from_pretrained_keras(repo_id) |
|
|
|
|
|
|
|
|
|
|
|
def predict(img): |
|
|
|
|
|
pred = learner.predict(img) |
|
|
|
|
|
mse = np.mean((img - pred) ** 2) |
|
|
|
|
|
anomaly_threshold = 0.1 |
|
|
|
|
|
if mse >= anomaly_threshold: |
|
|
anomaly_msg = "Posible anomalía significativa" |
|
|
else: |
|
|
anomaly_msg = "No anomalía" |
|
|
return {"Mensaje": anomaly_msg, "MSE": mse} |
|
|
|
|
|
|
|
|
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(28, 28)), outputs=[gr.outputs.Textbox(label="Mensaje"), gr.outputs.Textbox(label="MSE")], examples=['output_image.png', 'output_image_anomaly1.png']).launch(share=False) |
|
|
|
|
|
|
|
|
|