Spaces:
Sleeping
Sleeping
File size: 1,045 Bytes
09b3592 298829f ef0fb41 09b3592 |
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 28 29 30 31 |
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() |