Spaces:
Sleeping
Sleeping
File size: 1,965 Bytes
8b804f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import streamlit as st
import tensorflow as tf
from tensorflow.keras.applications import EfficientNetV2B0
from keras.layers import Flatten,Dense,Dropout,GlobalAveragePooling2D
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.preprocessing.image import img_to_array
from keras.models import Model
from tensorflow.keras.optimizers import Adam
import numpy as np
from huggingface_hub import hf_hub_url, cached_download
img_shape = (224,224,3)
model = EfficientNetV2B0(include_top = False,input_shape=img_shape)
flat_1=GlobalAveragePooling2D()(model.output)
capa_2 = Dense(512,activation='relu')(flat_1)
capa_drop = Dropout(0.5)(capa_2)
capa_3 = Dense(1,activation='sigmoid')(capa_drop)
model = Model(inputs=model.inputs,outputs = capa_3)
model.compile(optimizer=Adam(learning_rate=1e-4),loss="BinaryCrossentropy", metrics=["accuracy"])
#Subir los pesos del modelo
repo_id = "ferferefer/ACRIMA"
filename = "ACRIMA.h5" # o el path a tu SavedModel
# Obtener la URL y descargar el archivo (temporalmente)
model_file = cached_download(hf_hub_url(repo_id, filename))
# Cargar el modelo
model.load_weights(model_file)
st.title('ACRIMA Glaucoma Image Classifier')
input_image = st.file_uploader('Upload image')
if st.button('PREDICT'):
predict = load_img(input_image, target_size=img_shape)
predict_modified = img_to_array(predict)
predict_modified = np.expand_dims(predict_modified, axis=0)
result = model.predict(predict_modified)
if result < 0.5:
probability = 1 - result[0][0]
st.write(f"Healthy with {probability}%")
else:
probability = result[0][0]
st.write(f"Glaucoma with {probability}%")
image1 = load_img(input_image)
image1 = img_to_array(image1)
image1 = np.array(image1)
image1 = image1/255
st.image(image1, caption='Uploaded Image', use_column_width=True, clamp=True)
|