Sa-m commited on
Commit
c0d83e8
1 Parent(s): f0f8580

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -27,6 +27,8 @@ model=load_model('best_model.h5')
27
  # return result
28
 
29
 
 
 
30
  def classify_image(inp):
31
  np.random.seed(143)
32
  labels = {'Burger King': 0, 'KFC': 1, 'McDonalds': 2, 'Other': 3, 'Starbucks': 4, 'Subway': 5}
@@ -36,20 +38,17 @@ def classify_image(inp):
36
  prediction = model.predict(inp)
37
  predicted_class_indices = np.argmax(prediction, axis=1)
38
  result = {}
39
- # for i in range(len(predicted_class_indices)):
40
- # if predicted_class_indices[i] < NUM_CLASSES:
41
- # try:
42
- # label = labels[predicted_class_indices[i]]
43
- # result[label] = float(predicted_class_indices[i])
44
- # except KeyError:
45
- # print(f"KeyError: Label not found for index {predicted_class_indices[i]}")
46
  label_order = ["Burger King", "KFC", "McDonalds", "Other", "Starbucks", "Subway"]
47
 
48
- # Assuming prediction is a dictionary with label keys
49
- # result = [f"{label}: {prediction[label]:.2f}" for label in label_order]
50
- # return ", ".join(result)
51
- result = [f"{label}: {prediction[label]:.2f}" for label in labels]
52
- return ", ".join(result)
 
 
 
53
 
54
 
55
 
 
27
  # return result
28
 
29
 
30
+
31
+
32
  def classify_image(inp):
33
  np.random.seed(143)
34
  labels = {'Burger King': 0, 'KFC': 1, 'McDonalds': 2, 'Other': 3, 'Starbucks': 4, 'Subway': 5}
 
38
  prediction = model.predict(inp)
39
  predicted_class_indices = np.argmax(prediction, axis=1)
40
  result = {}
41
+
 
 
 
 
 
 
42
  label_order = ["Burger King", "KFC", "McDonalds", "Other", "Starbucks", "Subway"]
43
 
44
+ # Create a dictionary to hold the results
45
+ result = {label: f"{prediction[labels[label]]:.2f}" for label in label_order}
46
+
47
+ # Convert the dictionary to a string
48
+ result_str = ", ".join([f"{label}: {value}" for label, value in result.items()])
49
+
50
+ return result_str
51
+
52
 
53
 
54