Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from tensorflow.keras.preprocessing import image
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Cargar el modelo
|
| 8 |
+
model = load_model('https://huggingface.co/imanolcb/basicFruitClassifier/resolve/main/modelo_frutas_transfer.keras')
|
| 9 |
+
|
| 10 |
+
# Funci贸n para la predicci贸n
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = image.load_img(img, target_size=(150, 150))
|
| 13 |
+
img_array = image.img_to_array(img) / 255.0 # Normalizaci贸n
|
| 14 |
+
img_array = np.expand_dims(img_array, axis=0) # Cambiar la forma para predicci贸n
|
| 15 |
+
prediction = model.predict(img_array)
|
| 16 |
+
class_names = ['manzana', 'naranja', 'platano'] # Modificar con tus clases
|
| 17 |
+
predicted_class = class_names[np.argmax(prediction)]
|
| 18 |
+
return predicted_class
|
| 19 |
+
|
| 20 |
+
# Interfaz de Gradio
|
| 21 |
+
iface = gr.Interface(fn=predict,
|
| 22 |
+
inputs=gr.Image(type="filepath"),
|
| 23 |
+
outputs=gr.Text(),
|
| 24 |
+
live=True,
|
| 25 |
+
title="Clasificador de Frutas",
|
| 26 |
+
description="Cargar una imagen de fruta para clasificarla.")
|
| 27 |
+
|
| 28 |
+
# Iniciar la interfaz
|
| 29 |
+
iface.launch()
|