NourFakih commited on
Commit
9049ea4
·
verified ·
1 Parent(s): a0f1ab2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -24
app.py CHANGED
@@ -11,8 +11,6 @@ from spacy.cli import download
11
  import base64
12
  import numpy as np
13
  import datetime
14
- import time
15
- from streamlit_option_menu import option_menu
16
 
17
  # Download necessary NLP models
18
  nltk.download('wordnet')
@@ -77,20 +75,6 @@ def add_image_to_state(image, caption, capture_time):
77
  if len(st.session_state.captured_images) < 20:
78
  st.session_state.captured_images.append((img_str, caption, capture_time))
79
 
80
- def capture_images_from_webcam(num_images=5, interval=0.5):
81
- captured_images = []
82
- cap = cv2.VideoCapture(0)
83
- for _ in range(num_images):
84
- ret, frame = cap.read()
85
- if not ret:
86
- break
87
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
88
- pil_image = Image.fromarray(frame_rgb)
89
- captured_images.append(pil_image)
90
- time.sleep(interval)
91
- cap.release()
92
- return captured_images
93
-
94
  def page_image_captioning():
95
  st.title("Image Captioning")
96
  st.write("Your image captioning code here")
@@ -102,14 +86,15 @@ def page_video_captioning():
102
  def page_webcam_capture():
103
  st.title("Live Captioning with Webcam")
104
 
105
- if st.button("Capture 5 Images"):
106
- captured_images = capture_images_from_webcam()
107
- for img in captured_images:
108
- img_array = np.array(img)
109
- caption = generate_caption(img)
110
- capture_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
111
- add_image_to_state(img_array, caption, capture_time)
112
- st.image(img, caption=f"Caption: {caption}")
 
113
 
114
  if st.button('Stop'):
115
  st.write("Camera stopped.")
 
11
  import base64
12
  import numpy as np
13
  import datetime
 
 
14
 
15
  # Download necessary NLP models
16
  nltk.download('wordnet')
 
75
  if len(st.session_state.captured_images) < 20:
76
  st.session_state.captured_images.append((img_str, caption, capture_time))
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def page_image_captioning():
79
  st.title("Image Captioning")
80
  st.write("Your image captioning code here")
 
86
  def page_webcam_capture():
87
  st.title("Live Captioning with Webcam")
88
 
89
+ img_file = st.camera_input("Capture an image")
90
+
91
+ if img_file:
92
+ img = Image.open(img_file)
93
+ img_array = np.array(img)
94
+ caption = generate_caption(img)
95
+ capture_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
96
+ add_image_to_state(img_array, caption, capture_time)
97
+ st.image(img, caption=f"Caption: {caption}")
98
 
99
  if st.button('Stop'):
100
  st.write("Camera stopped.")