Aliashraf commited on
Commit
7e3eb15
·
verified ·
1 Parent(s): 3f35e59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -18,21 +18,36 @@ def process_frame(frame):
18
 
19
  def main():
20
  st.title("Smart Mirror AI")
 
 
21
  run = st.checkbox("Run Camera")
22
- cap = cv2.VideoCapture(0)
23
- frame_placeholder = st.empty()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- while run:
26
- success, frame = cap.read()
27
- if not success:
28
- st.write("Failed to capture video")
29
- break
30
- else:
31
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
32
- predictions = process_frame(frame)
33
- frame_placeholder.image(frame, channels="RGB")
34
- cap.release()
35
 
36
  if __name__ == "__main__":
37
  main()
38
 
 
 
18
 
19
  def main():
20
  st.title("Smart Mirror AI")
21
+
22
+ # Option to run camera or upload image
23
  run = st.checkbox("Run Camera")
24
+ uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
25
+
26
+ if run:
27
+ cap = cv2.VideoCapture(0)
28
+ frame_placeholder = st.empty()
29
+
30
+ while run:
31
+ success, frame = cap.read()
32
+ if not success:
33
+ st.write("Failed to capture video")
34
+ break
35
+ else:
36
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
37
+ predictions = process_frame(frame)
38
+ frame_placeholder.image(frame, channels="RGB")
39
+ cap.release()
40
 
41
+ elif uploaded_image is not None:
42
+ # If an image is uploaded, process it
43
+ image = Image.open(uploaded_image)
44
+ image = np.array(image)
45
+ image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
46
+ predictions = process_frame(image)
47
+ st.image(image, channels="BGR")
48
+ st.write(f"Predictions: {predictions}")
 
 
49
 
50
  if __name__ == "__main__":
51
  main()
52
 
53
+