Lau771 commited on
Commit
9b773b6
verified
1 Parent(s): eaf3188

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -42
app.py CHANGED
@@ -1,44 +1,7 @@
1
- import tensorflow as tf
2
  import gradio as gr
3
- import requests
4
- import numpy as np
5
- from PIL import Image
6
- from tensorflow.keras.applications.inception_v3 import decode_predictions
7
 
8
- # Cargar modelo preentrenado
9
- inception_net = tf.keras.applications.InceptionV3(weights='imagenet')
10
-
11
- # Descargar etiquetas
12
- response = requests.get("https://git.io/JJkYN")
13
- labels = response.text.split("\n")
14
-
15
- def clasifica_imagen(imagen):
16
- # Convertir el array a imagen PIL
17
- imagen = Image.fromarray(np.uint8(imagen))
18
-
19
- # Redimensionar la imagen a 299x299
20
- imagen = imagen.resize((299, 299))
21
-
22
- # Convertir la imagen a un array de NumPy
23
- imagen = np.array(imagen)
24
-
25
- # Asegurarse de que la imagen tiene 3 canales
26
- if imagen.ndim == 2:
27
- imagen = np.stack([imagen] * 3, axis=-1)
28
-
29
- # Preprocesar la imagen para el modelo
30
- imagen = tf.image.convert_image_dtype(imagen, dtype=tf.float32)
31
- imagen = tf.keras.applications.inception_v3.preprocess_input(imagen)
32
-
33
- # A帽adir una dimensi贸n batch
34
- imagen = tf.expand_dims(imagen, axis=0)
35
-
36
- # Realizar la predicci贸n
37
- predicciones = inception_net.predict(imagen)
38
- confidences = decode_predictions(predicciones, top=3)[0]
39
-
40
- return {etiqueta: float(confianza) for (_, etiqueta, confianza) in confidences}
41
-
42
- # Crear la interfaz de Gradio
43
- demo = gr.Interface(fn=clasifica_imagen, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3))
44
- demo.launch(debug=True)
 
 
1
  import gradio as gr
 
 
 
 
2
 
3
+ titulo = "Mi primer demo con Hugging Face"
4
+ descripcion = "Este es un demo ejecutado durante la clase."
5
+ gr.load("huggingface/microsoft/swin-tiny-patch4-window7-224",
6
+ title=titulo,
7
+ description=descripcion).launch(debug=True)