lydiazyang commited on
Commit
2a75739
·
1 Parent(s): 0d989d2

expanders for ingredients and nutrition on sidebar

Browse files
Files changed (1) hide show
  1. index.py +52 -34
index.py CHANGED
@@ -12,51 +12,70 @@ def main():
12
  st.sidebar.header('Ingredients & Nutrition')
13
 
14
 
15
- option1 = st.sidebar.checkbox('Banana')
16
- option2 = st.sidebar.checkbox('Strawberry')
17
- option3 = st.sidebar.checkbox('Kale')
18
- option4 = st.sidebar.checkbox('Orange Juice')
19
- option5 = st.sidebar.checkbox('Almond Milk')
20
- button_clicked = st.sidebar.button('Done')
21
- back_button_clicked = st.button('Camera')
22
- if button_clicked:
 
 
 
 
 
 
 
 
 
 
 
 
23
  displayRecipes()
24
 
25
- if not button_clicked or back_button_clicked:
26
- # Create a VideoCapture object to access the webcam
27
- cap = cv2.VideoCapture(0)
 
 
 
 
28
 
29
- # Set the video frame width and height (optional)
30
- cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
31
- cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
32
 
33
- # Check if the webcam is opened correctly
34
- if not cap.isOpened():
35
- st.error("Error: Unable to access the webcam.")
36
- return
37
 
38
- # Display a placeholder for the video stream
39
- video_placeholder = st.empty()
40
 
41
- # Button to capture image
42
- if st.button("Capture Image"):
43
- capture_image(cap)
 
44
 
45
- while True:
46
- # Read a frame from the webcam
47
- ret, frame = cap.read()
48
 
49
- if not ret:
50
- st.error("Error: Unable to read frame from the webcam.")
51
- break
52
 
53
- # Display the frame in the Streamlit app
54
- video_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB", use_column_width=True)
55
 
56
- # Release the VideoCapture and close the OpenCV window
57
- cap.release()
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()