Commit
·
58caebd
1
Parent(s):
3049c47
Fixed image
Browse files
index.py
CHANGED
|
@@ -7,18 +7,19 @@ from app import *
|
|
| 7 |
if not os.path.exists("captured_images"):
|
| 8 |
os.makedirs("captured_images")
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
| 12 |
st.title('RecipeMate')
|
| 13 |
|
| 14 |
st.sidebar.header('Ingredients & Nutrition')
|
| 15 |
-
|
| 16 |
# List of items
|
| 17 |
items = ['Item 1', 'Item 2', 'Item 3']
|
| 18 |
|
| 19 |
-
#list to of Ingredients camptured
|
| 20 |
-
ingredientsList =["apple", "orange", "mango", "potato", "cabbage", "carrot", "lentils"] #list()
|
| 21 |
-
|
| 22 |
# Define content for each item
|
| 23 |
content = {
|
| 24 |
'Item 1': "This is the content for Item 1",
|
|
@@ -30,8 +31,6 @@ def main():
|
|
| 30 |
for item in items:
|
| 31 |
with st.sidebar.expander(item):
|
| 32 |
st.write(content[item])
|
| 33 |
-
|
| 34 |
-
|
| 35 |
# Create a VideoCapture object to access the webcam
|
| 36 |
cap = cv2.VideoCapture(0)
|
| 37 |
|
|
@@ -46,20 +45,21 @@ def main():
|
|
| 46 |
|
| 47 |
# Display a placeholder for the video stream
|
| 48 |
video_placeholder = st.empty()
|
| 49 |
-
|
| 50 |
# Button to capture image
|
| 51 |
if st.button("Capture Image"):
|
| 52 |
-
image_path = capture_image(
|
| 53 |
classification = classifyImage(image_path)
|
| 54 |
-
ingredientsList.append(classification)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
ret, frame = cap.read()
|
| 64 |
|
| 65 |
if not ret:
|
|
@@ -68,10 +68,11 @@ def main():
|
|
| 68 |
|
| 69 |
# Display the frame in the Streamlit app
|
| 70 |
video_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
def displayRecipes(ingredientsList):
|
| 77 |
items = []
|
|
@@ -90,9 +91,20 @@ def displayRecipes(ingredientsList):
|
|
| 90 |
with st.expander(item["title"]):
|
| 91 |
st.write(item["content"])
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
def capture_image(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Read a frame from the webcam
|
| 97 |
ret, frame = cap.read()
|
| 98 |
|
|
@@ -104,6 +116,10 @@ def capture_image(cap):
|
|
| 104 |
image_path = f"captured_images/captured_image_{len(os.listdir('captured_images')) + 1}.jpg"
|
| 105 |
cv2.imwrite(image_path, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 106 |
st.success(f"Image captured and saved as {image_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
return image_path
|
| 108 |
|
| 109 |
|
|
|
|
| 7 |
if not os.path.exists("captured_images"):
|
| 8 |
os.makedirs("captured_images")
|
| 9 |
|
| 10 |
+
# Initialize the session state
|
| 11 |
+
session_state = st.session_state
|
| 12 |
+
if 'ingredientsList' not in session_state:
|
| 13 |
+
session_state['ingredientsList'] = []
|
| 14 |
|
| 15 |
+
def main():
|
| 16 |
+
|
| 17 |
st.title('RecipeMate')
|
| 18 |
|
| 19 |
st.sidebar.header('Ingredients & Nutrition')
|
|
|
|
| 20 |
# List of items
|
| 21 |
items = ['Item 1', 'Item 2', 'Item 3']
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
# Define content for each item
|
| 24 |
content = {
|
| 25 |
'Item 1': "This is the content for Item 1",
|
|
|
|
| 31 |
for item in items:
|
| 32 |
with st.sidebar.expander(item):
|
| 33 |
st.write(content[item])
|
|
|
|
|
|
|
| 34 |
# Create a VideoCapture object to access the webcam
|
| 35 |
cap = cv2.VideoCapture(0)
|
| 36 |
|
|
|
|
| 45 |
|
| 46 |
# Display a placeholder for the video stream
|
| 47 |
video_placeholder = st.empty()
|
|
|
|
| 48 |
# Button to capture image
|
| 49 |
if st.button("Capture Image"):
|
| 50 |
+
image_path = capture_image()
|
| 51 |
classification = classifyImage(image_path)
|
| 52 |
+
session_state['ingredientsList'].append(classification)
|
| 53 |
|
| 54 |
+
# Button to indicate done
|
| 55 |
+
done_button = st.sidebar.button('Done')
|
| 56 |
+
|
| 57 |
+
# Display the captured ingredients
|
| 58 |
+
st.write("Captured Ingredients:", session_state['ingredientsList'])
|
| 59 |
|
| 60 |
+
# Display recipes if "Done" is clicked
|
| 61 |
+
while not done_button:
|
| 62 |
+
# Read a frame from the webcam
|
| 63 |
ret, frame = cap.read()
|
| 64 |
|
| 65 |
if not ret:
|
|
|
|
| 68 |
|
| 69 |
# Display the frame in the Streamlit app
|
| 70 |
video_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True)
|
| 71 |
+
if done_button:
|
| 72 |
+
cap.release()
|
| 73 |
+
if session_state['ingredientsList']:
|
| 74 |
+
session_state['ingredientsList'].pop()
|
| 75 |
+
displayRecipes(session_state['ingredientsList'])
|
| 76 |
|
| 77 |
def displayRecipes(ingredientsList):
|
| 78 |
items = []
|
|
|
|
| 91 |
with st.expander(item["title"]):
|
| 92 |
st.write(item["content"])
|
| 93 |
|
|
|
|
| 94 |
|
| 95 |
+
def capture_image():
|
| 96 |
+
# Create a VideoCapture object to access the webcam
|
| 97 |
+
cap = cv2.VideoCapture(0)
|
| 98 |
+
|
| 99 |
+
# Set the video frame width and height (optional)
|
| 100 |
+
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 800)
|
| 101 |
+
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 400)
|
| 102 |
+
|
| 103 |
+
# Check if the webcam is opened correctly
|
| 104 |
+
if not cap.isOpened():
|
| 105 |
+
st.error("Error: Unable to access the webcam.")
|
| 106 |
+
return
|
| 107 |
+
|
| 108 |
# Read a frame from the webcam
|
| 109 |
ret, frame = cap.read()
|
| 110 |
|
|
|
|
| 116 |
image_path = f"captured_images/captured_image_{len(os.listdir('captured_images')) + 1}.jpg"
|
| 117 |
cv2.imwrite(image_path, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
| 118 |
st.success(f"Image captured and saved as {image_path}")
|
| 119 |
+
|
| 120 |
+
# Release the VideoCapture and close the OpenCV window
|
| 121 |
+
cap.release()
|
| 122 |
+
|
| 123 |
return image_path
|
| 124 |
|
| 125 |
|