frncscp commited on
Commit
f13b153
1 Parent(s): faae2ad

Update pages/Entorno de Ejecución.py

Browse files
Files changed (1) hide show
  1. pages/Entorno de Ejecución.py +7 -4
pages/Entorno de Ejecución.py CHANGED
@@ -37,6 +37,11 @@ def preprocess(file_uploader, module = 'cv2'): #makes the uploaded image readabl
37
  img = Image.open(file_uploader)
38
  return img
39
 
 
 
 
 
 
40
  @st.experimental_singleton
41
  def load_clip():
42
  classifier = pipeline("zero-shot-image-classification", model = 'openai/clip-vit-large-patch14-336')
@@ -206,11 +211,9 @@ with zero_shot:
206
  zs_classifier = classifier(img,
207
  candidate_labels = labels_for_classification)
208
 
209
- for clase in zs_classifier:
210
- if clase['label'] == 'A yellow deep fried smashed plantain':
211
- y_gorrito = clase["score"]
212
 
213
- if round(float(y_gorrito*100)) >= threshold:
214
  st.success("¡Patacón Detectado!")
215
  else:
216
  st.error("No se considera que haya un patacón en la imagen")
 
37
  img = Image.open(file_uploader)
38
  return img
39
 
40
+ def multiclass_prediction(classifier): #made for hf zero-shot pipeline results
41
+ score = (max([classifier[i]['score'] for i in range(len(classifier))]))
42
+ labels = [predict['label'] for predict in classifier if score == predict['score']]
43
+ return (labels[0] if len(labels) == 1 else labels, score)
44
+
45
  @st.experimental_singleton
46
  def load_clip():
47
  classifier = pipeline("zero-shot-image-classification", model = 'openai/clip-vit-large-patch14-336')
 
211
  zs_classifier = classifier(img,
212
  candidate_labels = labels_for_classification)
213
 
214
+ label, y_gorrito = multiclass_prediction(zs_classifier)
 
 
215
 
216
+ if label == "A yellow deep fried smashed plantain":
217
  st.success("¡Patacón Detectado!")
218
  else:
219
  st.error("No se considera que haya un patacón en la imagen")