Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
App.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Charger les modèles
|
| 7 |
+
model_TB = load_model("Tuberculosis_model.h5")
|
| 8 |
+
model_Pneumonia = load_model("Pneunomia_model.h5")
|
| 9 |
+
model_ImageTB = load_model("Image_TB_classifier.h5")
|
| 10 |
+
|
| 11 |
+
def predict(model_name, input_text):
|
| 12 |
+
# Transformer l'entrée texte en tableau numpy
|
| 13 |
+
# Exemple simple : input_text est des chiffres séparés par virgule
|
| 14 |
+
try:
|
| 15 |
+
input_array = np.array([[float(x) for x in input_text.split(",")]])
|
| 16 |
+
except:
|
| 17 |
+
return "Format d'entrée incorrect. Utilisez des nombres séparés par des virgules."
|
| 18 |
+
|
| 19 |
+
# Choix du modèle
|
| 20 |
+
if model_name == "Tuberculosis":
|
| 21 |
+
pred = model_TB.predict(input_array)
|
| 22 |
+
elif model_name == "Pneumonia":
|
| 23 |
+
pred = model_Pneumonia.predict(input_array)
|
| 24 |
+
elif model_name == "Image TB Classifier":
|
| 25 |
+
pred = model_ImageTB.predict(input_array)
|
| 26 |
+
else:
|
| 27 |
+
return "Modèle inconnu."
|
| 28 |
+
|
| 29 |
+
return str(pred[0])
|
| 30 |
+
|
| 31 |
+
# Interface Gradio
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=predict,
|
| 34 |
+
inputs=[
|
| 35 |
+
gr.Dropdown(["Tuberculosis", "Pneumonia", "Image TB Classifier"], label="Choisir le modèle"),
|
| 36 |
+
gr.Textbox(lines=1, placeholder="Entrée : valeurs séparées par virgule")
|
| 37 |
+
],
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="Prédiction IA TeamAI",
|
| 40 |
+
description="Tester les modèles Tuberculosis, Pneumonia, Image TB Classifier"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
iface.launch()
|