Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,11 +24,14 @@ detections = []
|
|
24 |
# =========================== ДЕТЕКЦИЯ ПЛОДА ============================
|
25 |
|
26 |
def detect_image(image_path: str, weight: float):
|
|
|
27 |
image = cv2.imread(image_path)
|
|
|
|
|
28 |
detections = model.predict(source=image_path, conf=0.5)
|
29 |
result_np_image = detections[0].plot()
|
30 |
result_np_image = cv2.cvtColor(result_np_image, cv2.COLOR_BGR2RGB)
|
31 |
-
|
32 |
detected_fruit = None
|
33 |
|
34 |
for det in detections:
|
@@ -38,13 +41,13 @@ def detect_image(image_path: str, weight: float):
|
|
38 |
break
|
39 |
|
40 |
if not detected_fruit:
|
41 |
-
return
|
42 |
|
43 |
fruit_name = fruits_data[detected_fruit]["name"]
|
44 |
price_per_kg = fruits_data[detected_fruit]["price_per_kg"]
|
45 |
total_price = round(price_per_kg * weight, 2)
|
46 |
|
47 |
-
return
|
48 |
|
49 |
|
50 |
# =========================== ЧЕК ============================
|
|
|
24 |
# =========================== ДЕТЕКЦИЯ ПЛОДА ============================
|
25 |
|
26 |
def detect_image(image_path: str, weight: float):
|
27 |
+
# Считываем изображение
|
28 |
image = cv2.imread(image_path)
|
29 |
+
|
30 |
+
# Выполняем детекцию
|
31 |
detections = model.predict(source=image_path, conf=0.5)
|
32 |
result_np_image = detections[0].plot()
|
33 |
result_np_image = cv2.cvtColor(result_np_image, cv2.COLOR_BGR2RGB)
|
34 |
+
|
35 |
detected_fruit = None
|
36 |
|
37 |
for det in detections:
|
|
|
41 |
break
|
42 |
|
43 |
if not detected_fruit:
|
44 |
+
return result_np_image, "Фрукт не обнаружен", None, None
|
45 |
|
46 |
fruit_name = fruits_data[detected_fruit]["name"]
|
47 |
price_per_kg = fruits_data[detected_fruit]["price_per_kg"]
|
48 |
total_price = round(price_per_kg * weight, 2)
|
49 |
|
50 |
+
return result_np_image, fruit_name, weight, total_price
|
51 |
|
52 |
|
53 |
# =========================== ЧЕК ============================
|