ItsEnder commited on
Commit
26c6fdc
verified
1 Parent(s): bdfd830

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+
6
+ # Cargar el modelo desde Hugging Face
7
+ model = tf.keras.models.load_model("ItsEnder/demo_model_deploy/resolve/main/model_mobileNetV2_MAX_70batch.h5")
8
+
9
+ # Funci贸n para preprocesar las im谩genes
10
+ def preprocess_image(img):
11
+ img = img.resize((224, 224))
12
+ img = np.array(img)
13
+ img = np.expand_dims(img, axis=0)
14
+ img = img / 255.0 # Normalizaci贸n
15
+ return img
16
+
17
+ # Funci贸n para hacer predicciones
18
+ def predict(img):
19
+ img_array = preprocess_image(img)
20
+ prediction = model.predict(img_array)
21
+ predicted_class = np.argmax(prediction)
22
+ return predicted_class
23
+
24
+ # Crear la interfaz con Gradio
25
+ interface = gr.Interface(
26
+ fn=predict,
27
+ inputs="image",
28
+ outputs="label",
29
+ title="Clasificaci贸n de im谩genes con MobileNetV2",
30
+ description="Sube una imagen y obt茅n la clase predicha."
31
+ )
32
+
33
+ # Ejecutar la interfaz
34
+ interface.launch()