import tensorflow as tf import numpy as np import gradio as gr from PIL import Image # 1. Charger le modèle entraîné (.h5) model = tf.keras.models.load_model("Tuberculosis_model.h5") # change le nom si besoin # 3. Fonction de prétraitement + prédiction def predict(image): image = image.resize((64, 64)) # Redimensionner à 64x64 image_array = np.array(image) / 255.0 # Normaliser image_array = image_array.reshape(1, 64, 64, 3) # Ajouter batch dimension prediction = model.predict(image_array)[0][0] # Get the single prediction value # Return the prediction as a string if prediction > 0.5: return f"Tuberculosis ({prediction:.4f})" else: return f"Normal ({prediction:.4f})" # 4. Interface Gradio gr.Interface( fn=predict, inputs=gr.Image(type="pil"), outputs="text", title="Tuberculosis Detection from Chest X-ray", description="Upload a chest X-ray image to get a prediction (Normal or Tuberculosis).", theme='JohnSmith9982/small_and_pretty' ).launch()