Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Charger le modèle sauvegardé
|
6 |
+
loaded_model = tf.keras.models.load_model("double_model.h5")
|
7 |
+
|
8 |
+
# Fonction pour prédire le double
|
9 |
+
def predict_double(x):
|
10 |
+
try:
|
11 |
+
x = float(x) # Conversion en float pour éviter les erreurs
|
12 |
+
x_array = np.array([[x]]) # Convertir en tableau NumPy
|
13 |
+
prediction = loaded_model.predict(x_array)[0][0]
|
14 |
+
return f"Le double de {x} est approximativement {prediction:.2f}"
|
15 |
+
except Exception as e:
|
16 |
+
return f"Erreur : {str(e)}"
|
17 |
+
|
18 |
+
# Interface Gradio
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=predict_double,
|
21 |
+
inputs=gr.Textbox(label="Entrez un nombre"),
|
22 |
+
outputs=gr.Textbox(label="Résultat"),
|
23 |
+
title="Calculateur de Double",
|
24 |
+
description="Entrez un chiffre, et le modèle donnera son double."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Lancer l'interface
|
28 |
+
if __name__ == "__main__":
|
29 |
+
interface.launch()
|