Spaces:
Sleeping
Sleeping
Update pages/Entorno de Ejecución.py
Browse files- pages/Entorno de Ejecución.py +21 -22
pages/Entorno de Ejecución.py
CHANGED
|
@@ -40,8 +40,6 @@ def preprocess(file_uploader, module = 'cv2'): #makes the uploaded image readabl
|
|
| 40 |
@st.experimental_singleton
|
| 41 |
def load_clip():
|
| 42 |
classifier = pipeline("zero-shot-image-classification", model = 'openai/clip-vit-large-patch14-336')
|
| 43 |
-
zsloaded = True
|
| 44 |
-
st.write('El modelo ha sido cargado, no es necesario volver a presionar el botón.')
|
| 45 |
return classifier
|
| 46 |
|
| 47 |
with cnn:
|
|
@@ -198,30 +196,31 @@ with zero_shot:
|
|
| 198 |
with col_b:
|
| 199 |
|
| 200 |
if st.button(key = 'clip_button', label = 'Cargar modelo de clasificación (puede tomar algo de tiempo)'):
|
| 201 |
-
|
| 202 |
|
| 203 |
|
| 204 |
if st.button(key = 'ZS_button', label ='¿Hay un patacón en la imagen?'):
|
| 205 |
if uploaded_file is not None:
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
if
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
st.
|
| 223 |
-
|
| 224 |
-
st.
|
|
|
|
| 225 |
else:
|
| 226 |
st.write("Asegúrate de haber subido correctamente la imagen.")
|
| 227 |
|
|
|
|
| 40 |
@st.experimental_singleton
|
| 41 |
def load_clip():
|
| 42 |
classifier = pipeline("zero-shot-image-classification", model = 'openai/clip-vit-large-patch14-336')
|
|
|
|
|
|
|
| 43 |
return classifier
|
| 44 |
|
| 45 |
with cnn:
|
|
|
|
| 196 |
with col_b:
|
| 197 |
|
| 198 |
if st.button(key = 'clip_button', label = 'Cargar modelo de clasificación (puede tomar algo de tiempo)'):
|
| 199 |
+
|
| 200 |
|
| 201 |
|
| 202 |
if st.button(key = 'ZS_button', label ='¿Hay un patacón en la imagen?'):
|
| 203 |
if uploaded_file is not None:
|
| 204 |
+
|
| 205 |
+
with st.spinner('Cargando el modelo (puede demorar hasta un minuto, pero después predice rápido)'):
|
| 206 |
+
classifier = load_clip()
|
| 207 |
+
|
| 208 |
+
with st.spinner('Cargando predicción...'):
|
| 209 |
+
img = preprocess(uploaded_file, module = 'pil')
|
| 210 |
+
zs_classifier = classifier(img,
|
| 211 |
+
candidate_labels = labels_for_classification)
|
| 212 |
+
|
| 213 |
+
for clase in zs_classifier:
|
| 214 |
+
if clase['label'] == 'A yellow deep fried smashed plantain':
|
| 215 |
+
y_gorrito = clase["score"]
|
| 216 |
+
|
| 217 |
+
if round(float(y_gorrito*100)) >= threshold:
|
| 218 |
+
st.success("¡Patacón Detectado!")
|
| 219 |
+
else:
|
| 220 |
+
st.error("No se considera que haya un patacón en la imagen")
|
| 221 |
+
|
| 222 |
+
st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
|
| 223 |
+
st.image(img)
|
| 224 |
else:
|
| 225 |
st.write("Asegúrate de haber subido correctamente la imagen.")
|
| 226 |
|