Spaces:
Running
Running
Update pages/Entorno de Ejecución.py
Browse files
pages/Entorno de Ejecución.py
CHANGED
@@ -157,11 +157,47 @@ with vit:
|
|
157 |
st.success("¡Patacón Detectado!")
|
158 |
else:
|
159 |
st.error("No se considera que haya un patacón en la imagen")
|
160 |
-
|
161 |
|
162 |
|
163 |
with zero_shot:
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
|
167 |
|
|
|
157 |
st.success("¡Patacón Detectado!")
|
158 |
else:
|
159 |
st.error("No se considera que haya un patacón en la imagen")
|
160 |
+
st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
|
161 |
|
162 |
|
163 |
with zero_shot:
|
164 |
+
|
165 |
+
col_a, col_b = st.columns(2)
|
166 |
+
|
167 |
+
with col_a:
|
168 |
+
|
169 |
+
st.title("Clasificación Zero-Shot")
|
170 |
+
st.caption("Usando [openai/clip-vit-large-patch14-336](https://huggingface.co/openai/clip-vit-large-patch14-336)")
|
171 |
+
|
172 |
+
clip = "openai/clip-vit-large-patch14-336"
|
173 |
+
classifier = pipeline("zero-shot-image-classification", model = clip)
|
174 |
+
|
175 |
+
labels_for_classification = ["A yellow deep fried smashed plantain",
|
176 |
+
"Fried food",
|
177 |
+
"Anything"]
|
178 |
+
|
179 |
+
uploaded_file = st.file_uploader(key = 'ZS_upload', label = 'Sube la imagen a clasificar',type= ['jpg','png', 'jpeg', 'jfif', 'webp', 'heic'])
|
180 |
+
threshold = st.slider('¿Cuál va a ser el límite desde donde se considere patacón? (se recomienda por encima del 80%)', 0, 100, 80, key = 'threshold_ZS')
|
181 |
+
|
182 |
+
if st.button(key = 'ZS_button', label ='¿Hay un patacón en la imagen?'):
|
183 |
+
if uploaded_file is not None:
|
184 |
+
with st.spinner('Cargando predicción...'):
|
185 |
+
img = preprocess(uploaded_file, module = 'pil')
|
186 |
+
flag = True
|
187 |
+
else:
|
188 |
+
st.write("Asegúrate de haber subido correctamente la imagen.")
|
189 |
+
|
190 |
+
|
191 |
+
with col_b:
|
192 |
+
if flag:
|
193 |
+
y_gorrito = (classifier(img,
|
194 |
+
candidate_labels = labels_for_classification)[1]["score"])
|
195 |
+
if round(float(y_gorrito*100)) >= threshold:
|
196 |
+
st.success("¡Patacón Detectado!")
|
197 |
+
else:
|
198 |
+
st.error("No se considera que haya un patacón en la imagen")
|
199 |
+
st.caption(f'La probabilidad de que la imagen tenga un patacón es del: {round(float(y_gorrito * 100), 2)}%')
|
200 |
+
|
201 |
|
202 |
|
203 |
|