Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import gradio as gr
|
|
9 |
import io
|
10 |
import base64
|
11 |
import tensorflow as tf
|
|
|
12 |
import zipfile
|
13 |
import os
|
14 |
|
@@ -28,7 +29,9 @@ extract_dir = "saved_model"
|
|
28 |
if not os.path.exists(extract_dir):
|
29 |
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
30 |
zip_ref.extractall(extract_dir)
|
31 |
-
|
|
|
|
|
32 |
|
33 |
# 🔹 Clases y niveles de riesgo
|
34 |
CLASSES = [
|
@@ -53,7 +56,7 @@ def preprocess_image_isic(image: Image.Image):
|
|
53 |
if img_array.shape[-1] == 4: # eliminar canal alpha si existe
|
54 |
img_array = img_array[..., :3]
|
55 |
img_array = np.expand_dims(img_array, axis=0) # batch dimension
|
56 |
-
return img_array
|
57 |
|
58 |
def analizar_lesion_combined(img):
|
59 |
# Convertir imagen para Fastai
|
@@ -73,9 +76,10 @@ def analizar_lesion_combined(img):
|
|
73 |
prob_malignant = float(probs_fast_mal[1]) # índice 1 = maligno
|
74 |
pred_fast_type, _, probs_fast_type = model_norm2000.predict(img_fastai)
|
75 |
|
76 |
-
# Modelo TensorFlow ISIC
|
77 |
x_isic = preprocess_image_isic(img)
|
78 |
-
|
|
|
79 |
pred_idx_isic = int(np.argmax(preds_isic))
|
80 |
pred_class_isic = CLASSES[pred_idx_isic]
|
81 |
confidence_isic = preds_isic[pred_idx_isic]
|
@@ -139,4 +143,3 @@ demo = gr.Interface(
|
|
139 |
|
140 |
if __name__ == "__main__":
|
141 |
demo.launch()
|
142 |
-
|
|
|
9 |
import io
|
10 |
import base64
|
11 |
import tensorflow as tf
|
12 |
+
import keras # <--- nuevo import para TFSMLayer
|
13 |
import zipfile
|
14 |
import os
|
15 |
|
|
|
29 |
if not os.path.exists(extract_dir):
|
30 |
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
31 |
zip_ref.extractall(extract_dir)
|
32 |
+
|
33 |
+
# Cargar modelo con TFSMLayer (solo para inferencia)
|
34 |
+
model_isic = keras.layers.TFSMLayer(extract_dir, call_endpoint='serving_default')
|
35 |
|
36 |
# 🔹 Clases y niveles de riesgo
|
37 |
CLASSES = [
|
|
|
56 |
if img_array.shape[-1] == 4: # eliminar canal alpha si existe
|
57 |
img_array = img_array[..., :3]
|
58 |
img_array = np.expand_dims(img_array, axis=0) # batch dimension
|
59 |
+
return img_array.astype(np.float32)
|
60 |
|
61 |
def analizar_lesion_combined(img):
|
62 |
# Convertir imagen para Fastai
|
|
|
76 |
prob_malignant = float(probs_fast_mal[1]) # índice 1 = maligno
|
77 |
pred_fast_type, _, probs_fast_type = model_norm2000.predict(img_fastai)
|
78 |
|
79 |
+
# Modelo TensorFlow ISIC (usando TFSMLayer)
|
80 |
x_isic = preprocess_image_isic(img)
|
81 |
+
preds_isic_tensor = model_isic(x_isic) # devuelve tensor
|
82 |
+
preds_isic = preds_isic_tensor.numpy()[0] # convertir a numpy y quitar batch dim
|
83 |
pred_idx_isic = int(np.argmax(preds_isic))
|
84 |
pred_class_isic = CLASSES[pred_idx_isic]
|
85 |
confidence_isic = preds_isic[pred_idx_isic]
|
|
|
143 |
|
144 |
if __name__ == "__main__":
|
145 |
demo.launch()
|
|