Update app.py
Browse files
app.py
CHANGED
@@ -113,9 +113,13 @@ def process_frame(frame):
|
|
113 |
"emotion": emotion,
|
114 |
"timestamp": timestamp
|
115 |
}
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# Draw bounding box and label
|
121 |
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
@@ -126,7 +130,6 @@ def process_frame(frame):
|
|
126 |
|
127 |
return frame, result_text
|
128 |
|
129 |
-
|
130 |
# Video feed display
|
131 |
def video_feed(video_source):
|
132 |
frame_placeholder = st.empty() # Placeholder for displaying video frames
|
@@ -174,16 +177,18 @@ elif upload_choice == "Upload Video":
|
|
174 |
video_source = cv2.VideoCapture(tfile.name)
|
175 |
video_feed(video_source)
|
176 |
|
177 |
-
# Display the records stored in MongoDB with
|
178 |
st.markdown("### MongoDB Records")
|
179 |
-
records = collection.find().sort("timestamp", -1) #
|
180 |
|
181 |
for record in records:
|
182 |
-
col1, col2 = st.columns([3, 3])
|
183 |
with col1:
|
184 |
st.write(f"**Name**: {record['name']}")
|
185 |
with col2:
|
186 |
st.write(f"**Emotion**: {record['emotion']}")
|
|
|
|
|
187 |
|
188 |
# Delete record
|
189 |
delete_button = st.button("Delete", key=f"delete_{record['_id']}")
|
|
|
113 |
"emotion": emotion,
|
114 |
"timestamp": timestamp
|
115 |
}
|
116 |
+
|
117 |
+
# Check if the same record already exists (to prevent duplicates)
|
118 |
+
existing_record = collection.find_one({"name": name, "timestamp": timestamp})
|
119 |
+
if not existing_record:
|
120 |
+
# Insert the data into MongoDB
|
121 |
+
collection.insert_one(document)
|
122 |
+
print(f"Data inserted into MongoDB: {document}")
|
123 |
|
124 |
# Draw bounding box and label
|
125 |
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
|
|
130 |
|
131 |
return frame, result_text
|
132 |
|
|
|
133 |
# Video feed display
|
134 |
def video_feed(video_source):
|
135 |
frame_placeholder = st.empty() # Placeholder for displaying video frames
|
|
|
177 |
video_source = cv2.VideoCapture(tfile.name)
|
178 |
video_feed(video_source)
|
179 |
|
180 |
+
# Display the latest 5 records stored in MongoDB with timestamp and proper alignment
|
181 |
st.markdown("### MongoDB Records")
|
182 |
+
records = collection.find().sort("timestamp", -1).limit(5) # Limit to 5 records
|
183 |
|
184 |
for record in records:
|
185 |
+
col1, col2, col3 = st.columns([3, 3, 2])
|
186 |
with col1:
|
187 |
st.write(f"**Name**: {record['name']}")
|
188 |
with col2:
|
189 |
st.write(f"**Emotion**: {record['emotion']}")
|
190 |
+
with col3:
|
191 |
+
st.write(f"**Timestamp**: {record['timestamp']}")
|
192 |
|
193 |
# Delete record
|
194 |
delete_button = st.button("Delete", key=f"delete_{record['_id']}")
|