ferferefer commited on
Commit
8b804f0
1 Parent(s): 55e5665

Upload app.py

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