Commit
·
2a75739
1
Parent(s):
0d989d2
expanders for ingredients and nutrition on sidebar
Browse files
index.py
CHANGED
|
@@ -12,51 +12,70 @@ def main():
|
|
| 12 |
st.sidebar.header('Ingredients & Nutrition')
|
| 13 |
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
displayRecipes()
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
|
|
|
| 59 |
def displayRecipes():
|
|
|
|
| 60 |
items = [
|
| 61 |
{"title": "Item 1", "content": "Content for Item 1."},
|
| 62 |
{"title": "Item 2", "content": "Content for Item 2."},
|
|
@@ -69,7 +88,6 @@ def displayRecipes():
|
|
| 69 |
st.write(item["content"])
|
| 70 |
|
| 71 |
|
| 72 |
-
|
| 73 |
def capture_image(cap):
|
| 74 |
# Read a frame from the webcam
|
| 75 |
ret, frame = cap.read()
|
|
|
|
| 12 |
st.sidebar.header('Ingredients & Nutrition')
|
| 13 |
|
| 14 |
|
| 15 |
+
# List of items
|
| 16 |
+
items = ['Banana', 'Apple', 'Orange']
|
| 17 |
+
|
| 18 |
+
# Define content for each item
|
| 19 |
+
content = {
|
| 20 |
+
'Banana': "1oo kcal/each",
|
| 21 |
+
'Apple': "80 kcal/each",
|
| 22 |
+
'Orange': "80 kcal/each"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Display expanders for each item
|
| 26 |
+
for item in items:
|
| 27 |
+
with st.sidebar.expander(item):
|
| 28 |
+
st.write(content[item])
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
done_clicked = st.sidebar.button('Done')
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if done_clicked:
|
| 35 |
displayRecipes()
|
| 36 |
|
| 37 |
+
|
| 38 |
+
if not done_clicked:
|
| 39 |
+
vidCapture()
|
| 40 |
+
|
| 41 |
+
def vidCapture():
|
| 42 |
+
# Create a VideoCapture object to access the webcam
|
| 43 |
+
cap = cv2.VideoCapture(0)
|
| 44 |
|
| 45 |
+
# Set the video frame width and height (optional)
|
| 46 |
+
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
| 47 |
+
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
| 48 |
|
| 49 |
+
# Check if the webcam is opened correctly
|
| 50 |
+
if not cap.isOpened():
|
| 51 |
+
st.error("Error: Unable to access the webcam.")
|
| 52 |
+
return
|
| 53 |
|
| 54 |
+
# Display a placeholder for the video stream
|
| 55 |
+
video_placeholder = st.empty()
|
| 56 |
|
| 57 |
+
# Button to capture image
|
| 58 |
+
capture_button_clicked = st.button("Capture Image")
|
| 59 |
+
if capture_button_clicked:
|
| 60 |
+
capture_image(cap)
|
| 61 |
|
| 62 |
+
while True:
|
| 63 |
+
# Read a frame from the webcam
|
| 64 |
+
ret, frame = cap.read()
|
| 65 |
|
| 66 |
+
if not ret:
|
| 67 |
+
st.error("Error: Unable to read frame from the webcam.")
|
| 68 |
+
break
|
| 69 |
|
| 70 |
+
# Display the frame in the Streamlit app
|
| 71 |
+
video_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True)
|
| 72 |
|
| 73 |
+
# Release the VideoCapture and close the OpenCV window
|
| 74 |
+
cap.release()
|
| 75 |
|
| 76 |
+
|
| 77 |
def displayRecipes():
|
| 78 |
+
|
| 79 |
items = [
|
| 80 |
{"title": "Item 1", "content": "Content for Item 1."},
|
| 81 |
{"title": "Item 2", "content": "Content for Item 2."},
|
|
|
|
| 88 |
st.write(item["content"])
|
| 89 |
|
| 90 |
|
|
|
|
| 91 |
def capture_image(cap):
|
| 92 |
# Read a frame from the webcam
|
| 93 |
ret, frame = cap.read()
|