Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344import gradio as grimport tensorflow as tfimport numpy as npIMG_SIZE = (224, 224)CLASS_NAMES = ['no_valido', 'valido']def preprocess_image(img):img = tf.image.resize(img, IMG_SIZE)img_array = tf.expand_dims(img, 0)img_array = img_array / 255.0return img_arraydef predict(rx_image, keras_model_file):model_path = "temp_model.keras"with open(model_path, "wb") as f:f.write(keras_model_file.read())model = tf.keras.models.load_model(model_path)img_array = preprocess_image(rx_image)preds = model.predict(img_array)score = tf.nn.softmax(preds[0])predicted_index = np.argmax(score)confidence = np.max(score) * 100predicted_class = CLASS_NAMES[predicted_index]other_index = 1 - predicted_indexother_class = CLASS_NAMES[other_index]other_confidence = score[other_index] * 100return f"Resultado: {predicted_class.upper()} ({confidence:.2f}%)\n" + \f"Probabilidad {other_class}: {other_confidence:.2f}%"iface = gr.Interface(fn=predict,inputs=[gr.Image(type="numpy", label="Sube tu RX"),gr.File(file_types=[".keras"], label="Sube tu modelo Keras")],outputs=gr.Textbox(label="Resultado"))iface.launch()
app.py+44