Spaces:
Running
Running
Merge pull request #1 from MSU-AI/project-structure
Browse files- .gitignore +8 -0
- README.md +61 -0
- app/main.py +48 -0
- requirements.txt +9 -0
- safetycam/__init__.py +0 -0
- safetycam/sentiment.py +4 -0
- setup.py +11 -0
.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# files meant to exist locally only
|
2 |
+
env/
|
3 |
+
scratch/
|
4 |
+
*.egg-info/*
|
5 |
+
|
6 |
+
# python related files
|
7 |
+
*.pyc
|
8 |
+
**/__pycache__/
|
README.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Safety Cam
|
2 |
+
Safety Cam is a project developed by the Artificial Intelligence Club (AI Club) at Michigan State University (MSU). The goal of this project is to develop a camera capable of detecting dangers using camera visuals and sound detection.
|
3 |
+
|
4 |
+
## How it Works
|
5 |
+
The Safety Cam uses a combination of computer vision and sound detection algorithms to identify potentially dangerous situations.
|
6 |
+
The camera captures live footage and processes it in real-time using various computer vision techniques such as object detection and tracking.
|
7 |
+
At the same time, the camera also analyzes the sound in the environment and identifies sounds and speeches that potentially signify dangers.
|
8 |
+
If the camera detects a dangerous situation, it alerts the user through a mobile app and sends an emergency alert to predefined contacts.
|
9 |
+
|
10 |
+
## Getting Started
|
11 |
+
To get started with the Safety Cam, you will need the following:
|
12 |
+
- A computer with a camera and microphone
|
13 |
+
- Python 3.10 or later installed
|
14 |
+
- Git
|
15 |
+
|
16 |
+
To set up the Safety Cam, follow the steps below:
|
17 |
+
1. Clone the Safety Cam repository to your computer using the following command:
|
18 |
+
```
|
19 |
+
git clone https://github.com/MSU-AI/safety-camera.git
|
20 |
+
```
|
21 |
+
2. Install the required dependencies by running the following command in the Safety Cam directory:
|
22 |
+
```
|
23 |
+
pip install -r requirements.txt
|
24 |
+
```
|
25 |
+
3. Start the Safety Cam by running:
|
26 |
+
```
|
27 |
+
cd app/
|
28 |
+
streamlit run main.py
|
29 |
+
```
|
30 |
+
4. The Safety Cam web app will open in your default web browser.
|
31 |
+
5. Click on the "Start" button to start the camera stream.
|
32 |
+
6. The camera will start capturing footage and processing it in real-time.
|
33 |
+
7. If the Safety Cam detects a potentially dangerous situation, it will display an alert on the screen.
|
34 |
+
8. To stop the camera stream, click on the "Stop Stream" button.
|
35 |
+
|
36 |
+
## Contributing
|
37 |
+
We welcome contributions to the Safety Cam project. If you would like to contribute, please follow the steps below:
|
38 |
+
1. Set up a virtual environment named `env`:
|
39 |
+
```
|
40 |
+
python -m venv env
|
41 |
+
```
|
42 |
+
2. Activate the virtual environment. On Windows, run:
|
43 |
+
```
|
44 |
+
env\Scripts\activate
|
45 |
+
```
|
46 |
+
On Linux or macOS, run:
|
47 |
+
```
|
48 |
+
source env/bin/activate
|
49 |
+
```
|
50 |
+
3. Install the required dependencies by running the following command in the Safety Cam directory:
|
51 |
+
```
|
52 |
+
pip install -r requirements.txt
|
53 |
+
```
|
54 |
+
4. Install `safetycam` as a local editable package:
|
55 |
+
```
|
56 |
+
pip install -e .
|
57 |
+
```
|
58 |
+
|
59 |
+
## License
|
60 |
+
The Safety Cam project is licensed under the MIT License.
|
61 |
+
See the [LICENSE](LICENSE) file for more information.
|
app/main.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_webrtc import webrtc_streamer
|
3 |
+
import speech_recognition as sr
|
4 |
+
import time
|
5 |
+
|
6 |
+
def speech_to_text_microphone():
|
7 |
+
# initialize recognizer class (for recognizing the speech)
|
8 |
+
r = sr.Recognizer()
|
9 |
+
|
10 |
+
# Reading Microphone as source
|
11 |
+
# listening the speech and store in audio_text variable
|
12 |
+
with sr.Microphone() as source:
|
13 |
+
audio_text = r.listen(source)
|
14 |
+
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
|
15 |
+
try:
|
16 |
+
# using google speech recognition
|
17 |
+
return r.recognize_google(audio_text)
|
18 |
+
except:
|
19 |
+
return ""
|
20 |
+
|
21 |
+
|
22 |
+
audio = ""
|
23 |
+
st.title("SafetyCam")
|
24 |
+
|
25 |
+
webrtc_streamer(key="video")
|
26 |
+
def live_caption():
|
27 |
+
text = ""
|
28 |
+
# Initialize recognizer and microphone objects
|
29 |
+
r = sr.Recognizer()
|
30 |
+
mic = sr.Microphone()
|
31 |
+
|
32 |
+
# Set minimum energy threshold to account for ambient noise
|
33 |
+
with mic as source:
|
34 |
+
r.adjust_for_ambient_noise(source)
|
35 |
+
|
36 |
+
# Continuously listen to microphone input and print live caption
|
37 |
+
with mic as source:
|
38 |
+
while True:
|
39 |
+
try:
|
40 |
+
audio = r.listen(source)
|
41 |
+
text = r.recognize_google(audio)
|
42 |
+
print(text)
|
43 |
+
st.write(text)
|
44 |
+
except sr.UnknownValueError:
|
45 |
+
# Handle unrecognized speech
|
46 |
+
pass
|
47 |
+
if st.button("Start Live Caption"):
|
48 |
+
live_caption()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ipykernel>=6.21.3,<=6.22
|
2 |
+
mediapipe>=0.9.1.0,<=0.10
|
3 |
+
numpy>=1.24.2,<=1.25
|
4 |
+
pandas>=1.5.3,<=1.6
|
5 |
+
PyAudio>=0.2.13,<=0.3
|
6 |
+
pydub>=0.25.1,<=0.26
|
7 |
+
SpeechRecognition>=3.10.0,<=3.11
|
8 |
+
streamlit>=1.20.0,<=1.21
|
9 |
+
streamlit-webrtc>=0.45.0,<=0.46
|
safetycam/__init__.py
ADDED
File without changes
|
safetycam/sentiment.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
def dummy(msg):
|
4 |
+
return msg.upper()
|
setup.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
from distutils.core import setup
|
3 |
+
|
4 |
+
setup(
|
5 |
+
name='Safety Cam',
|
6 |
+
version='0.1',
|
7 |
+
author='MSU AI Club (Spring 2023)',
|
8 |
+
packages=[
|
9 |
+
'safetycam',
|
10 |
+
]
|
11 |
+
)
|