Spaces:
Paused
Paused
Commit
•
3f68dec
1
Parent(s):
4aa61c6
try except
Browse files- food_nonfood.py +10 -4
food_nonfood.py
CHANGED
@@ -21,10 +21,16 @@ classifier = pipeline("zero-shot-classification", model="roberta-large-mnli")
|
|
21 |
|
22 |
# Classify item as food or non-food
|
23 |
def classify_as_food_nonfood(item):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# print(f"Item: {item}, Label: {label}, Score: {score}")
|
29 |
return label, score
|
30 |
|
|
|
21 |
|
22 |
# Classify item as food or non-food
|
23 |
def classify_as_food_nonfood(item):
|
24 |
+
try:
|
25 |
+
cleaned_item = item.strip().lower()
|
26 |
+
result = classifier(cleaned_item, candidate_labels=["food", "non-food"])
|
27 |
+
label = result["labels"][0]
|
28 |
+
score = result["scores"][0]
|
29 |
+
except Exception as e:
|
30 |
+
print(f"Error: {e}")
|
31 |
+
print(f"item is: {item}")
|
32 |
+
label = "non-food"
|
33 |
+
score = 0.0
|
34 |
# print(f"Item: {item}, Label: {label}, Score: {score}")
|
35 |
return label, score
|
36 |
|