LovnishVerma commited on
Commit
55220d5
·
verified ·
1 Parent(s): e8a2db8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -109,21 +109,18 @@ def video_feed(video_source):
109
  text_placeholder.markdown(f"<h3 style='text-align: center;'>{result_text}</h3>", unsafe_allow_html=True)
110
 
111
  # Sidebar for video or image upload
112
- upload_choice = st.sidebar.radio("Choose input source", ["Upload Video", "Upload Image", "Camera"])
113
 
114
  if upload_choice == "Camera":
115
- # Access camera
116
- video_source = cv2.VideoCapture(0)
117
- video_feed(video_source)
118
 
119
- elif upload_choice == "Upload Video":
120
- uploaded_video = st.file_uploader("Upload Video", type=["mp4", "mov", "avi", "mkv", "webm"])
121
- if uploaded_video:
122
- # Temporarily save the video to disk
123
- with tempfile.NamedTemporaryFile(delete=False) as tfile:
124
- tfile.write(uploaded_video.read())
125
- video_source = cv2.VideoCapture(tfile.name)
126
- video_feed(video_source)
127
 
128
  elif upload_choice == "Upload Image":
129
  uploaded_image = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg", "gif"])
@@ -134,4 +131,13 @@ elif upload_choice == "Upload Image":
134
  st.image(frame, caption='Processed Image', use_column_width=True)
135
  st.markdown(f"<h3 style='text-align: center;'>{result_text}</h3>", unsafe_allow_html=True)
136
 
 
 
 
 
 
 
 
 
 
137
  st.sidebar.write("Emotion Labels: Angry, Fear, Happy, Neutral, Sad, Surprise")
 
109
  text_placeholder.markdown(f"<h3 style='text-align: center;'>{result_text}</h3>", unsafe_allow_html=True)
110
 
111
  # Sidebar for video or image upload
112
+ upload_choice = st.sidebar.radio("Choose input source", ["Upload Image", "Upload Video", "Camera"])
113
 
114
  if upload_choice == "Camera":
115
+ # Use Streamlit's built-in camera input widget for capturing images from the webcam
116
+ image = st.camera_input("Take a picture")
 
117
 
118
+ if image is not None:
119
+ # Convert the image to a numpy array
120
+ frame = np.array(Image.open(image))
121
+ frame, result_text = process_frame(frame)
122
+ st.image(frame, caption='Processed Image', use_column_width=True)
123
+ st.markdown(f"<h3 style='text-align: center;'>{result_text}</h3>", unsafe_allow_html=True)
 
 
124
 
125
  elif upload_choice == "Upload Image":
126
  uploaded_image = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg", "gif"])
 
131
  st.image(frame, caption='Processed Image', use_column_width=True)
132
  st.markdown(f"<h3 style='text-align: center;'>{result_text}</h3>", unsafe_allow_html=True)
133
 
134
+ elif upload_choice == "Upload Video":
135
+ uploaded_video = st.file_uploader("Upload Video", type=["mp4", "mov", "avi", "mkv", "webm"])
136
+ if uploaded_video:
137
+ # Temporarily save the video to disk
138
+ with tempfile.NamedTemporaryFile(delete=False) as tfile:
139
+ tfile.write(uploaded_video.read())
140
+ video_source = cv2.VideoCapture(tfile.name)
141
+ video_feed(video_source)
142
+
143
  st.sidebar.write("Emotion Labels: Angry, Fear, Happy, Neutral, Sad, Surprise")