Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,8 @@ def predict_labels_and_probabilities(image_path):
|
|
| 22 |
step_size = 100 # Step size for the grid
|
| 23 |
predictions = []
|
| 24 |
|
| 25 |
-
for y in range(0,
|
| 26 |
-
for x in range(0,
|
| 27 |
patch = img_rgb[y:y+img_height, x:x+img_width]
|
| 28 |
patch_resized = cv2.resize(patch, (img_height, img_width))
|
| 29 |
patch_array = image.img_to_array(patch_resized)
|
|
@@ -43,8 +43,10 @@ def predict_labels_and_probabilities(image_path):
|
|
| 43 |
|
| 44 |
if probability > 0.5: # Threshold to filter out low confidence predictions
|
| 45 |
predictions.append((predicted_class, probability, x, y, x+img_width, y+img_height))
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
return predictions
|
| 48 |
|
| 49 |
# Streamlit App
|
| 50 |
st.title("Intelligent Recipe Finder Classification")
|
|
@@ -56,7 +58,7 @@ if uploaded_file is not None:
|
|
| 56 |
st.image(uploaded_file, caption='Uploaded Ingredient Image.', use_column_width=True)
|
| 57 |
|
| 58 |
# Perform the prediction and display the results
|
| 59 |
-
predictions = predict_labels_and_probabilities(uploaded_file)
|
| 60 |
st.write("Predictions for detected ingredients in the image:")
|
| 61 |
|
| 62 |
for i, (label, probability, x1, y1, x2, y2) in enumerate(predictions):
|
|
@@ -65,8 +67,5 @@ if uploaded_file is not None:
|
|
| 65 |
st.write(f"Probability: {probability}")
|
| 66 |
st.write(f"Location: ({x1}, {y1}) to ({x2}, {y2})")
|
| 67 |
|
| 68 |
-
# Draw rectangle around detected ingredients
|
| 69 |
-
cv2.rectangle(img_rgb, (x1, y1), (x2, y2), (255, 0, 0), 2)
|
| 70 |
-
|
| 71 |
# Display the image with rectangles
|
| 72 |
-
st.image(
|
|
|
|
| 22 |
step_size = 100 # Step size for the grid
|
| 23 |
predictions = []
|
| 24 |
|
| 25 |
+
for y in range(0, img_rgb.shape[0] - img_height, step_size):
|
| 26 |
+
for x in range(0, img_rgb.shape[1] - img_width, step_size):
|
| 27 |
patch = img_rgb[y:y+img_height, x:x+img_width]
|
| 28 |
patch_resized = cv2.resize(patch, (img_height, img_width))
|
| 29 |
patch_array = image.img_to_array(patch_resized)
|
|
|
|
| 43 |
|
| 44 |
if probability > 0.5: # Threshold to filter out low confidence predictions
|
| 45 |
predictions.append((predicted_class, probability, x, y, x+img_width, y+img_height))
|
| 46 |
+
# Draw rectangle around detected ingredients
|
| 47 |
+
cv2.rectangle(img_rgb, (x, y), (x+img_width, y+img_height), (255, 0, 0), 2)
|
| 48 |
|
| 49 |
+
return predictions, img_rgb
|
| 50 |
|
| 51 |
# Streamlit App
|
| 52 |
st.title("Intelligent Recipe Finder Classification")
|
|
|
|
| 58 |
st.image(uploaded_file, caption='Uploaded Ingredient Image.', use_column_width=True)
|
| 59 |
|
| 60 |
# Perform the prediction and display the results
|
| 61 |
+
predictions, img_with_boxes = predict_labels_and_probabilities(uploaded_file)
|
| 62 |
st.write("Predictions for detected ingredients in the image:")
|
| 63 |
|
| 64 |
for i, (label, probability, x1, y1, x2, y2) in enumerate(predictions):
|
|
|
|
| 67 |
st.write(f"Probability: {probability}")
|
| 68 |
st.write(f"Location: ({x1}, {y1}) to ({x2}, {y2})")
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
# Display the image with rectangles
|
| 71 |
+
st.image(img_with_boxes, caption='Detected Ingredients', use_column_width=True)
|