Treelar commited on
Commit
6214467
1 Parent(s): ff7134f

[fix] background without leaves causing error due to parsing

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -27,9 +27,16 @@ def predict(image):
27
  label = model.config.id2label[label_index]
28
 
29
  # Split the label into leaf category and disease name
 
30
  label_parts = label.split("___")
31
  leaf_category = label_parts[0]
32
- disease_name = label_parts[1]
 
 
 
 
 
 
33
 
34
  # Calculate the percentage breakdown of predicted diseases
35
  percentage_breakdown = {disease: round(float(probability[0, index]) * 100, 2) for index, disease in enumerate(model.config.label2id)}
 
27
  label = model.config.id2label[label_index]
28
 
29
  # Split the label into leaf category and disease name
30
+
31
  label_parts = label.split("___")
32
  leaf_category = label_parts[0]
33
+
34
+ disease_name: str = ""
35
+ if len(label_parts) == 1:
36
+ # if label parts only has one part, assume "background with leaves" as the category and "N/A as the disease name"
37
+ disease_name = "N/A"
38
+ else:
39
+ disease_name = label_parts[1]
40
 
41
  # Calculate the percentage breakdown of predicted diseases
42
  percentage_breakdown = {disease: round(float(probability[0, index]) * 100, 2) for index, disease in enumerate(model.config.label2id)}