Spaces:
Sleeping
Sleeping
Update pages/Entorno de Ejecución.py
Browse files
pages/Entorno de Ejecución.py
CHANGED
|
@@ -37,10 +37,13 @@ def preprocess(file_uploader, module = 'cv2'): #makes the uploaded image readabl
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@st.cache_resource
|
| 46 |
def load_clip():
|
|
@@ -227,7 +230,7 @@ with zero_shot:
|
|
| 227 |
zs_classifier = classifier(img,
|
| 228 |
candidate_labels = labels_for_classification)
|
| 229 |
|
| 230 |
-
label, y_gorrito = multiclass_prediction(zs_classifier)
|
| 231 |
|
| 232 |
if label == "A yellow deep fried smashed plantain":
|
| 233 |
st.success("¡Patacón Detectado!")
|
|
|
|
| 37 |
img = Image.open(file_uploader)
|
| 38 |
return img
|
| 39 |
|
| 40 |
+
def multiclass_prediction(classifier, important_class): #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 |
+
for clase in classifier:
|
| 44 |
+
if clase['label'] == important_class:
|
| 45 |
+
class_score = clase['score']
|
| 46 |
+
return (labels[0] if len(labels) == 1 else labels, score, class_score)
|
| 47 |
|
| 48 |
@st.cache_resource
|
| 49 |
def load_clip():
|
|
|
|
| 230 |
zs_classifier = classifier(img,
|
| 231 |
candidate_labels = labels_for_classification)
|
| 232 |
|
| 233 |
+
label, _, y_gorrito = multiclass_prediction(zs_classifier)
|
| 234 |
|
| 235 |
if label == "A yellow deep fried smashed plantain":
|
| 236 |
st.success("¡Patacón Detectado!")
|