ferferefer commited on
Commit
dbde183
1 Parent(s): a4a53b8

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_3 = Dense(1,activation='sigmoid')(flat_1)
17
+ model = Model(inputs=model.inputs,outputs = capa_3)
18
+ model.compile(optimizer=Adam(learning_rate=1e-4),loss="BinaryCrossentropy", metrics=["accuracy"])
19
+ #Subir los pesos del modelo
20
+ repo_id = "ferferefer/ACRIMA"
21
+ filename = "ACRIMA.h5" # o el path a tu SavedModel
22
+ # Obtener la URL y descargar el archivo (temporalmente)
23
+ model_file = cached_download(hf_hub_url(repo_id, filename))
24
+ # Cargar el modelo
25
+ model.load_weights(model_file)
26
+
27
+
28
+ st.title('ACRIMA Glaucoma Image Classifier')
29
+ input_image = st.file_uploader('Upload image')
30
+
31
+
32
+ if st.button('PREDICT'):
33
+
34
+ predict = load_img(input_image, target_size=img_shape)
35
+ predict_modified = img_to_array(predict)
36
+ predict_modified = np.expand_dims(predict_modified, axis=0)
37
+ result = model.predict(predict_modified)
38
+ if result < 0.5:
39
+ probability = 1 - result[0][0]
40
+ st.write(f"Healthy with {probability}%")
41
+
42
+ else:
43
+ probability = result[0][0]
44
+ st.write(f"Glaucoma with {probability}%")
45
+
46
+ image1 = load_img(input_image)
47
+ image1 = img_to_array(image1)
48
+ image1 = np.array(image1)
49
+ image1 = image1/255
50
+
51
+
52
+
53
+ st.image(image1, caption='Uploaded Image', use_column_width=True, clamp=True)
54
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ keras
4
+ transformers
5
+ huggingface_hub
6
+ numpy