Supermedel commited on
Commit
af3722b
1 Parent(s): 5f683d6

Upload 11 files

Browse files
Files changed (11) hide show
  1. 000114.png +0 -0
  2. 000117 (3).png +0 -0
  3. 000118 (5).png +0 -0
  4. 000122.png +0 -0
  5. 000126.png +0 -0
  6. 000131.png +0 -0
  7. 7 - Copy.png +0 -0
  8. 8 (2).png +0 -0
  9. app.py +54 -0
  10. model_cancer2.h5 +3 -0
  11. requeriments +3 -0
000114.png ADDED
000117 (3).png ADDED
000118 (5).png ADDED
000122.png ADDED
000126.png ADDED
000131.png ADDED
7 - Copy.png ADDED
8 (2).png ADDED
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Importamos librerías
2
+ %pip install gradio
3
+ from PIL import Image
4
+ import gradio as gr
5
+ import numpy as np
6
+ import os
7
+ import matplotlib.image as mpimg
8
+ import matplotlib.pyplot as plt
9
+
10
+ import tensorflow as tf
11
+ from tensorflow import keras
12
+ from tensorflow.keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img
13
+ from tensorflow.keras.callbacks import ReduceLROnPlateau
14
+ from keras.models import Sequential
15
+ from keras.layers import Dense,MaxPooling2D,Dropout,Flatten,BatchNormalization,Conv2D
16
+
17
+ #cargo el modelo preentrenado
18
+ model = keras.models.load_model('/content/drive/MyDrive/model_cancer2.h5')
19
+
20
+ # Definir las etiquetas de clase
21
+ class_names = ['adenocarcinoma', 'large_carcinoma', 'squamous_carcinoma', 'normal']
22
+
23
+ # Función para realizar predicciones en una imagen
24
+ def predict_image(img):
25
+ # Preprocesar la imagen para que coincida con el formato de entrada del modelo
26
+ img_array = img_to_array(img) # Convertir la imagen a un array
27
+ img_array = tf.image.resize(img_array, [224, 224]) # Ajustar al tamaño de entrada del modelo
28
+ img_array = np.expand_dims(img_array, axis=0)
29
+ img_array = img_array.copy() / 255.0 # Normalizar los valores de píxeles al rango [0, 1]
30
+
31
+
32
+ # Hacer la predicción
33
+ predictions = model.predict(img_array)
34
+ # Devolver un diccionario con las confidencias de cada clase
35
+ return {class_names[i]: float(predictions[0][i]) for i in range(len(class_names))}
36
+
37
+ # Configuración de la interfaz Gradio con ejemplos predefinidos
38
+ iface = gr.Interface(
39
+ fn=predict_image,
40
+ inputs=gr.Image(),
41
+ outputs=gr.Label(num_top_classes=len(class_names)),
42
+ examples=[
43
+ [np.array(Image.open("/content/Data/test/adenocarcinoma/000114 (5).png"))],
44
+ [np.array(Image.open("/content/Data/test/adenocarcinoma/000120.png"))],
45
+ [np.array(Image.open("/content/Data/test/large.cell.carcinoma/000111.png"))],
46
+ [np.array(Image.open("/content/Data/test/large.cell.carcinoma/000120.png"))],
47
+ [np.array(Image.open("/content/Data/test/normal/12 (2) - Copy.png"))],
48
+ [np.array(Image.open("/content/Data/test/normal/7.png"))],
49
+ [np.array(Image.open("/content/Data/test/squamous.cell.carcinoma/000116 (5).png"))],
50
+ [np.array(Image.open("/content/Data/test/squamous.cell.carcinoma/000121 (5).png"))],
51
+ [np.array(Image.open("/content/Data/test/squamous.cell.carcinoma/000168 (2).png"))]
52
+ ]
53
+ )
54
+ iface.launch()
model_cancer2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b76fe4c9983173f3dfeb4fdfc3b7bd8da48a0ae66632d58987a3796ae2888d0
3
+ size 213105008
requeriments ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow==2.15
2
+ keras==2.15
3
+ numpy==1.24