Update app.py
Browse files
app.py
CHANGED
@@ -20,17 +20,22 @@ def detect_objects(image):
|
|
20 |
|
21 |
# Menghitung jumlah objek per kelas
|
22 |
class_count = {}
|
|
|
|
|
23 |
for prediction in predictions['predictions']:
|
24 |
class_name = prediction['class']
|
25 |
if class_name in class_count:
|
26 |
class_count[class_name] += 1
|
27 |
else:
|
28 |
class_count[class_name] = 1
|
|
|
29 |
|
30 |
# Menyusun output berupa string hasil perhitungan
|
31 |
-
result_text = "
|
32 |
for class_name, count in class_count.items():
|
33 |
-
result_text += f"{class_name}: {count}
|
|
|
|
|
34 |
|
35 |
# Menyimpan gambar dengan prediksi
|
36 |
output_image = model.predict(temp_file_path, confidence=60, overlap=80).save("/tmp/prediction.jpg")
|
|
|
20 |
|
21 |
# Menghitung jumlah objek per kelas
|
22 |
class_count = {}
|
23 |
+
total_count = 0 # Menyimpan total jumlah objek
|
24 |
+
|
25 |
for prediction in predictions['predictions']:
|
26 |
class_name = prediction['class']
|
27 |
if class_name in class_count:
|
28 |
class_count[class_name] += 1
|
29 |
else:
|
30 |
class_count[class_name] = 1
|
31 |
+
total_count += 1 # Tambah jumlah objek untuk setiap prediksi
|
32 |
|
33 |
# Menyusun output berupa string hasil perhitungan
|
34 |
+
result_text = "Product Nestle:\n"
|
35 |
for class_name, count in class_count.items():
|
36 |
+
result_text += f"{class_name}: {count} \n"
|
37 |
+
|
38 |
+
result_text += f"\nTotal Product Nestle: {total_count}"
|
39 |
|
40 |
# Menyimpan gambar dengan prediksi
|
41 |
output_image = model.predict(temp_file_path, confidence=60, overlap=80).save("/tmp/prediction.jpg")
|