Spaces:
Running
Running
Update pages/Entorno de Ejecución.py
Browse files
pages/Entorno de Ejecución.py
CHANGED
@@ -22,7 +22,8 @@ st.sidebar.write("contact@patacotron.tech")
|
|
22 |
|
23 |
cnn, vit, zero_shot, autoencoder, svm, iforest, gan = st.tabs(["CNN", "ViT", "Zero-Shot", "Autoencoder", "OC-SVM", 'iForest', 'GAN'])
|
24 |
|
25 |
-
|
|
|
26 |
y_gorrito = 0
|
27 |
raw_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
28 |
img = cv2.resize(img, (IMAGE_WIDTH, IMAGE_HEIGHT))
|
@@ -38,6 +39,13 @@ def preprocess(file_uploader, module = 'cv2'): #makes the uploaded image readabl
|
|
38 |
img = Image.open(file_uploader)
|
39 |
return img
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
with cnn:
|
42 |
|
43 |
col_a, col_b, = st.columns(2)
|
@@ -187,15 +195,14 @@ with zero_shot:
|
|
187 |
|
188 |
uploaded_file = st.file_uploader(key = 'ZS_upload', label = 'Sube la imagen a clasificar',type= ['jpg','png', 'jpeg', 'jfif', 'webp', 'heic'])
|
189 |
threshold = st.slider('¿Cuál va a ser el límite desde donde se considere patacón? (se recomienda por encima del 33.33%)', 0, 100, 34, key = 'threshold_ZS')
|
190 |
-
|
191 |
with col_b:
|
192 |
|
193 |
if st.button(key = 'clip_button', label = 'Cargar modelo de clasificación (puede tomar algo de tiempo)'):
|
194 |
with st.spinner("Cargando modelo de clasificación..."):
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
if st.button(key = 'ZS_button', label ='¿Hay un patacón en la imagen?'):
|
200 |
if uploaded_file is not None:
|
201 |
if zsloaded:
|
@@ -216,7 +223,7 @@ with zero_shot:
|
|
216 |
st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
|
217 |
st.image(img)
|
218 |
else:
|
219 |
-
st.write('Primero se necesita cargar el modelo.')
|
220 |
else:
|
221 |
st.write("Asegúrate de haber subido correctamente la imagen.")
|
222 |
|
|
|
22 |
|
23 |
cnn, vit, zero_shot, autoencoder, svm, iforest, gan = st.tabs(["CNN", "ViT", "Zero-Shot", "Autoencoder", "OC-SVM", 'iForest', 'GAN'])
|
24 |
|
25 |
+
@st.cache_resource
|
26 |
+
def predict(model_list, weights, img):
|
27 |
y_gorrito = 0
|
28 |
raw_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
29 |
img = cv2.resize(img, (IMAGE_WIDTH, IMAGE_HEIGHT))
|
|
|
39 |
img = Image.open(file_uploader)
|
40 |
return img
|
41 |
|
42 |
+
@st.cache_resource
|
43 |
+
def load_clip():
|
44 |
+
classifier = pipeline("zero-shot-image-classification", model = 'openai/clip-vit-large-patch14-336')
|
45 |
+
zsloaded = True
|
46 |
+
st.write('El modelo ha sido cargado, no es necesario volver a presionar el botón.')
|
47 |
+
return classifier
|
48 |
+
|
49 |
with cnn:
|
50 |
|
51 |
col_a, col_b, = st.columns(2)
|
|
|
195 |
|
196 |
uploaded_file = st.file_uploader(key = 'ZS_upload', label = 'Sube la imagen a clasificar',type= ['jpg','png', 'jpeg', 'jfif', 'webp', 'heic'])
|
197 |
threshold = st.slider('¿Cuál va a ser el límite desde donde se considere patacón? (se recomienda por encima del 33.33%)', 0, 100, 34, key = 'threshold_ZS')
|
198 |
+
|
199 |
with col_b:
|
200 |
|
201 |
if st.button(key = 'clip_button', label = 'Cargar modelo de clasificación (puede tomar algo de tiempo)'):
|
202 |
with st.spinner("Cargando modelo de clasificación..."):
|
203 |
+
classifier = load_clip()
|
204 |
+
zsloaded = True
|
205 |
+
|
|
|
206 |
if st.button(key = 'ZS_button', label ='¿Hay un patacón en la imagen?'):
|
207 |
if uploaded_file is not None:
|
208 |
if zsloaded:
|
|
|
223 |
st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
|
224 |
st.image(img)
|
225 |
else:
|
226 |
+
st.write('Primero se necesita cargar el modelo.', zsloaded)
|
227 |
else:
|
228 |
st.write("Asegúrate de haber subido correctamente la imagen.")
|
229 |
|