Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 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 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
|