Spaces:
Runtime error
Runtime error
Commit
路
9a1a08b
1
Parent(s):
796c231
V1
Browse files- app.py +46 -0
- requirements.txt +3 -0
- test_img/coche-test.jpg +0 -0
- test_img/pajaro-test.jpg +0 -0
- test_img/perro-test.png +0 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from huggingface_hub import from_pretrained_keras
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
model = from_pretrained_keras("keras-io/semi-supervised-classification-simclr")
|
| 7 |
+
|
| 8 |
+
labels_gradio = ["Avi贸n", "Pajaro", "Coche", "Gato", "Ciervo", "Perro", "Caballo", "Mono", "Barco", "Cami贸n"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def predict(imput_image):
|
| 12 |
+
image = tf.constant(imput_image)
|
| 13 |
+
image = tf.reshape(image, [-1, 96, 96, 3])
|
| 14 |
+
pred = model.predict(image)
|
| 15 |
+
pred_list = pred[0, :]
|
| 16 |
+
pred_softmax = np.exp(pred_list)/np.sum(np.exp(pred_list))
|
| 17 |
+
softmax_list = pred_softmax.tolist()
|
| 18 |
+
return {labels_gradio[i]: softmax_list[i] for i in range(10)}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
image = gr.inputs.Image(shape=(96, 96))
|
| 22 |
+
label = gr.outputs.Label(num_top_classes=4)
|
| 23 |
+
|
| 24 |
+
pie_pag = """<center>
|
| 25 |
+
Modelo: <a href='https://huggingface.co/keras-io/semi-supervised-classification-simclr' target='_blank'>keras.io</a>
|
| 26 |
+
Basado en el Space: <a href='https://huggingface.co/spaces/keras-io/semi-supervised-classification' target='_blank'>Andr谩s B茅res</a>
|
| 27 |
+
Autor: <a href='https://huggingface.co/machde' target='_blank'>Manuel Chac贸n De Dios</a>"""
|
| 28 |
+
|
| 29 |
+
titulo = "Mini clasificador"
|
| 30 |
+
descripcion = """<center>Clasificador capaz de etiquetar si es un Avi贸n, Pajaro, Coche,
|
| 31 |
+
Gato, Ciervo, Perro, Caballo, Mono, Barco, Cami贸n</center>"""
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Iface = gr.Interface(
|
| 37 |
+
fn=predict,
|
| 38 |
+
inputs=image,
|
| 39 |
+
outputs=label,
|
| 40 |
+
layout="vertical",
|
| 41 |
+
theme="seafoam",
|
| 42 |
+
examples=[["test_img/pajaro-test.jpeg"], ["test_img/coche-test.jpg"], ["test_img/perro-test.jpg"]],
|
| 43 |
+
title=titulo,
|
| 44 |
+
article=pie_pag,
|
| 45 |
+
description=descripcion,
|
| 46 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow >=2.6.0
|
| 2 |
+
gradio
|
| 3 |
+
jinja2
|
test_img/coche-test.jpg
ADDED
|
test_img/pajaro-test.jpg
ADDED
|
test_img/perro-test.png
ADDED
|