Spaces:
Runtime error
Runtime error
| 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() | |