Spaces:
Runtime error
Runtime error
pyesonekyaw
commited on
Commit
•
bd7d1bb
1
Parent(s):
7fc0592
added show_error=True
Browse files
app.py
CHANGED
@@ -77,45 +77,48 @@ def predict_image(inp):
|
|
77 |
"""
|
78 |
Performs inference for a given input image and returns the prediction and CAM image.
|
79 |
"""
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
|
121 |
with gr.Blocks(title="Trash Classification", css="#custom_header {min-height: 3rem} #custom_title {min-height: 3rem; text-align: center}") as demo:
|
|
|
77 |
"""
|
78 |
Performs inference for a given input image and returns the prediction and CAM image.
|
79 |
"""
|
80 |
+
try:
|
81 |
+
material_label, material_label_idx, material_probs = materials_model.predict(inp)
|
82 |
+
material_preds = {name: prob for name, prob in zip(material_names, material_probs.tolist())}
|
83 |
+
|
84 |
+
if material_label == 'paper':
|
85 |
+
specific_label, specific_label_idx, specific_probs = paper_model.predict(inp)
|
86 |
+
specific_preds = {name: prob for name, prob in zip(paper_names, specific_probs.tolist())}
|
87 |
+
specific_label = paper_names[int(specific_label_idx)]
|
88 |
+
recyclable_qn = paper_item_num_dict[specific_label][0]
|
89 |
+
recyclable_advice = paper_item_num_dict[specific_label][1]
|
90 |
+
|
91 |
+
elif material_label == 'plastic':
|
92 |
+
specific_label, specific_label_idx, specific_probs = plastic_model.predict(inp)
|
93 |
+
specific_preds = {name: prob for name, prob in zip(plastic_names, specific_probs.tolist())}
|
94 |
+
specific_label = plastic_names[int(specific_label_idx)]
|
95 |
+
recyclable_qn = plastic_item_num_dict[specific_label][0]
|
96 |
+
recyclable_advice = plastic_item_num_dict[specific_label][1]
|
97 |
+
|
98 |
+
elif material_label == 'glass':
|
99 |
+
specific_label, specific_label_idx, specific_probs = glass_model.predict(inp)
|
100 |
+
specific_preds = {name: prob for name, prob in zip(glass_names, specific_probs.tolist())}
|
101 |
+
specific_label = glass_names[int(specific_label_idx)]
|
102 |
+
recyclable_qn = glass_item_num_dict[specific_label][0]
|
103 |
+
recyclable_advice = glass_item_num_dict[specific_label][1]
|
104 |
+
|
105 |
+
elif material_label == 'metal':
|
106 |
+
specific_label, specific_label_idx, specific_probs = metal_model.predict(inp)
|
107 |
+
specific_preds = {name: prob for name, prob in zip(metal_names, specific_probs.tolist())}
|
108 |
+
specific_label = metal_names[int(specific_label_idx)]
|
109 |
+
recyclable_qn = metal_item_num_dict[specific_label][0]
|
110 |
+
recyclable_advice = metal_item_num_dict[specific_label][1]
|
111 |
+
|
112 |
+
elif material_label == 'others':
|
113 |
+
specific_label, specific_label_idx, specific_probs = others_model.predict(inp)
|
114 |
+
specific_preds = {name: prob for name, prob in zip(other_names, specific_probs.tolist())}
|
115 |
+
specific_label = other_names[int(specific_label_idx)]
|
116 |
+
recyclable_qn = others_item_num_dict[specific_label][0]
|
117 |
+
recyclable_advice = others_item_num_dict[specific_label][1]
|
118 |
+
|
119 |
+
return material_preds, specific_preds, recyclable_qn, recyclable_advice
|
120 |
+
except:
|
121 |
+
raise Exception("Invalid file format! Please only upload .jpg or .png files!")
|
122 |
|
123 |
|
124 |
with gr.Blocks(title="Trash Classification", css="#custom_header {min-height: 3rem} #custom_title {min-height: 3rem; text-align: center}") as demo:
|