Spaces:
Runtime error
Runtime error
File size: 849 Bytes
73575e3 | 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 | import gradio as gr
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2, decode_predictions, preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np
model = MobileNetV2(weights="imagenet")
def clasificar_img(img):
img = img.resize((224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)
preds = model.predict(img_array)
decoded = decode_predictions(preds, top=1)[0][0]
return f"Predicci贸n: {decoded[1]} (Confianza: {round(decoded[2] * 100, 2)}%)"
demo = gr.Interface(
fn=clasificar_img,
inputs=gr.Image(type="pil"),
outputs="text",
title="Clasificaci贸n de Im谩genes con MobileNetV2",
description="Sube una imagen y recibe una predicci贸n de su contenido."
)
demo.launch()
|