Skip to content

Commit

Permalink
update requirements/update install
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarnard committed Feb 4, 2023
1 parent de0add2 commit f98459d
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 112 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions etc/mema.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rhasspy_reload = 10

#FIXME: logging used now: prepare for deb like directory structure, need config file though
debug = yes
logfile_name = /home/pi/var/spool/mema3.log
logfile_name = /home/pi/mema/var/spool/mema3.log

#FIXME: whisper.cpp soon set to false, to leave things unlabelled etc., since currently external service
#FIXME: needs to be on script by script basis, actually
Expand All @@ -28,7 +28,7 @@ picture_command = libcamera-jpeg --nopreview -o
#picture command = DISPLAY=:0 libcamera-jpeg -o

## --- problematic video section --- ##
# this doesn't do sound currently, need to recompile ffmpeg or move to cvlc?
#FIXME: this doesn't do sound currently, need to recompile ffmpeg or move to cvlc?
# changed to libcamera 12/12/2022
video_command = libcamera-vid --nopreview -t video_maximum -o true_file_name
#FIXME: thirty secs for testing, this is milliseconds, kill button?
Expand Down
10 changes: 4 additions & 6 deletions etc/mema_pi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rhasspy_reload = 10

#FIXME: logging used now: prepare for deb like directory structure, need config file though
debug = yes
logfile_name = var/spool/mema3.log
logfile_name = /home/pi/mema/var/spool/mema3.log

#FIXME: whisper.cpp soon set to false, to leave things unlabelled etc., since currently external service
#FIXME: needs to be on script by script basis, actually
Expand Down Expand Up @@ -45,8 +45,7 @@ record_command = arecord -q -c 2 -f S16_LE -r 16000 -Dhw:3 --duration
# record maximum in seconds
audio_maximum = 30

#FIXME: produces a mosaic of all jpg stills, need something a little more sophisticated
mosaic_command = /usr/bin/montage /home/pi/mema/static/media/pic/*.jpg /home/pi/mema/static/media/pic/montage.jpg
mosaic_command = /usr/bin/montage /home/pi/mema/static/media/pic/*.jpg /home/pi/mema/static/media/pic/montage.jpg

#pi record using voice bonnet
#record_command = arecord -f cd -c 2 -D plug:dsnooped --duration 30
Expand All @@ -55,10 +54,8 @@ mosaic_command = /usr/bin/montage /home/pi/mema/static/media/pic/*.jpg /hom
label_program = /home/pi/mema/label_video.py

#FIXME: this is problematic, replace with jaro
#xdg_open_command = handlr launch x-scheme-handler/http -- http://localhost:8000/memories.html
#jaro_open_command = jaro http://localhost:8000/memories.html
xdg_open_command = http://localhost:8000/memories.html
#xdg_search_open = xdg-open https://google.com?q=mema


keyword_slot_file = ~/.config/rhasspy/profiles/en/slots/keywords

Expand Down Expand Up @@ -93,6 +90,7 @@ ok_then = OK_then
done = Done_and_dusted
what_kind = What_kind_of_pie_would_you_like?
ok_going = OK_here_we_go
say_please = say_please_why_dont_you
#FIXME: should be [literals][en] as above
Expand Down
8 changes: 4 additions & 4 deletions etc/systemd/intent_server.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ Description=Intent Server for Mema: Executes Known Voice Commands
After=network.target

[Service]
#User=hbarnard
User=pi
#Group=users
PermissionsStartOnly = true
PIDFile=/run/mema/intent_server.pid
WorkingDirectory=/usr/share/pyshared/
Environment=REPLICATE_API_TOKEN=
ExecStartPre = /bin/mkdir /run/mema
#ExecStartPre = /bin/mkdir /run/mema

ExecStart=/bin/sh -c "cd /home/pi/mema && /usr/local/bin/gunicorn -k uvicorn.workers.UvicornWorker intent_server:app -b 0.0.0.0:8000 --pid /run/mema/intent_server.pid"
ExecStart=/bin/sh -c "cd /home/pi/mema && /usr/local/bin/gunicorn -k uvicorn.workers.UvicornWorker intent_server:app -b 0.0.0.0:8000 --pid /var/mema/intent_server.pid"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
ExecStopPost=/bin/rmdir /run/mema/
#ExecStopPost=/bin/rmdir /run/mema/

[Install]
WantedBy=multi-user.target
21 changes: 21 additions & 0 deletions etc/systemd/intent_server.service.barnard
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]

Description=Intent Server for Mema: Executes Known Voice Commands
After=network.target

[Service]
User=hbarnard
#Group=users
PermissionsStartOnly = true
PIDFile=/run/mema/intent_server.pid
WorkingDirectory=/usr/share/pyshared/
Environment=REPLICATE_API_TOKEN=
#ExecStartPre = /bin/mkdir /run/mema

ExecStart=/bin/sh -c "cd /home/hbarnard/mema && /usr/local/bin/gunicorn -k uvicorn.workers.UvicornWorker intent_server:app -b 0.0.0.0:8000 --pid /var/mema/intent_server.pid"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
#ExecStopPost=/bin/rmdir /run/mema/

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions face_unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ def face_unlock(config):
cap = cv.VideoCapture(0)
#cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
if not cap.isOpened():
log.debugging('no image')
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
X_face_locations = face_recognition.face_locations(frame,1,model="hog")
#X_face_locations = face_recognition.face_locations(frame,no_of_times_to_upsample=1,model="cnn")
#logging.debug(X_face_locations)
title = 'Mema3 Unlock'

Expand Down
66 changes: 12 additions & 54 deletions flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"from": "",
"to": "",
"reg": false,
"x": 280,
"y": 100,
"x": 160,
"y": 280,
"wires": [
[
"d3aca42480bbaa79"
Expand Down Expand Up @@ -146,83 +146,41 @@
"id": "d3aca42480bbaa79",
"type": "switch",
"z": "2f1e41c5.19c21e",
"name": "",
"property": "intent.name",
"name": "Intent Switch",
"property": "payload.intent.intentName",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "GetStory",
"v": "Unlock",
"vt": "str"
},
{
"t": "eq",
"v": "GetStory",
"v": "Unlock",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 310,
"y": 200,
"x": 330,
"y": 220,
"wires": [
[
"20d1e591be301077"
],
[
"aaf280e3c40ad2ce"
]
]
},
{
"id": "aaf280e3c40ad2ce",
"type": "http request",
"z": "2f1e41c5.19c21e",
"name": "",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "http://localhost:8000",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 510,
"y": 200,
"wires": [
[
"c2929d043f0ad428"
]
[]
]
},
{
"id": "0a0b641fa9c3eef1",
"type": "comment",
"z": "2f1e41c5.19c21e",
"name": "Complex requests with variables",
"name": "Complex requests with variables. later on",
"info": "",
"x": 570,
"y": 160,
"wires": []
},
{
"id": "c2929d043f0ad428",
"type": "debug",
"z": "2f1e41c5.19c21e",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 200,
"x": 480,
"y": 260,
"wires": []
},
{
Expand Down
58 changes: 48 additions & 10 deletions install.sh → install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# npm install node-red-contrib-pythonshell
# python modules for face unlock
#
# timesync doesn't work hence ntpspec
# FIXME timesync doesn't work hence ntpspec/clock pi problems 'anyway'

echo '*-------------------------------------------------------------------------------*'
echo 'this will try to install mema3, control-c to abort, sleeping for 10 seconds'
echo 'make sure that the system date on the Pi is correct otherwise certs are invalid'
echo '*-------------------------------------------------------------------------------*'
sleep 10
echo '*-------------------------------------------------------------------------------*'
echo 'system upgrade to start with'
echo 'system update and upgrade to start with'
echo '*-------------------------------------------------------------------------------*'
apt update
apt dist-upgrade
apt upgrade

echo '*-------------------------------------------------------------------------------*'
echo 'making media directories'
Expand All @@ -33,32 +33,70 @@ echo '*------------------------------------------------------------------------
apt install python3-pip
apt install python3-numpy
apt install python3-pycurl
apt install python3-pyaudio
apt install python3-matplotlib python3-tk
apt install mosquitto mosquitto-dev
apt install sqlite3 ntpspec
apt install sqlite3
apt install ntpsec
# may or may not need ffmpeg for sample conversion
apt install ffmpeg portaudio portaudio19-dev fswebcam curl python3-pyaudio guile2.0
apt install ffmpeg
apt install portaudio portaudio19-dev
#FIXME: fswebcam is only used on the laptop, libcamera on the pi
apt install fswebcam
apt install curl
# FIXME: is this guile2.0 or 3.0 either will 'work'
apt install guile3.0
sudo apt install docker.io
echo '*-------------------------------------------------------------------------------*'
echo 'installing mema3'
echo 'install python3 packages, make take a while'
echo '*-------------------------------------------------------------------------------*'
sudo -H pip install -r requirements.txt
sudo -H pip install -r requirements/requirements.txt
echo '*-------------------------------------------------------------------------------*'
echo 'installing intent server service'
cp etc/systemd/intent_server.service /etc/systemd/system/
cp etc/mema_pi.ini etc/mema.ini
systemctl daemon-reload
systemctl enable intent_server
echo 'installing face unlock server service'
cp etc/systemd/unlock_server.service /etc/systemd/system/
systemctl enable unlock_server

#FIXME: need to copy based on system pi or laptop
printf 'Is this a pi (y/n)? '
old_stty_cfg=$(stty -g)
stty raw -echo ; answer=$(head -c 1) ; stty $old_stty_cfg # Careful playing with stty
if [ "$answer" != "${answer#[Yy]}" ];then
cp etc/mema_pi.ini etc/mema.ini
cp associations /home/pi/.config
echo 'mema_pi.ini copied to mema.ini'
else
cp etc/mema_laptop.ini etc/mema.ini
cp associations /home/hbarnard/.config
echo 'assuming laptop, mema_laptop.ini copied to mema.ini'
fi

echo '*-------------------------------------------------------------------------------*'
echo 'trying to start containers'
usermod -aG docker pi
docker run -d --network host --name mema_rhasspy --restart unless-stopped -v "$HOME/.config/rhasspy/profiles:/profiles" -v "/etc/localtime:/etc/localtime:ro" --device /dev/snd:/dev/snd rhasspy/rhasspy --user-profiles /profiles --profile en
sudo docker run --network host -d --restart unless-stopped --name mema_mimic3 -v "${HOME}/.local/share/mycroft/mimic3:/home/mimic3/.local/share/mycroft/mimic3" 'mycroftai/mimic3'
docker run --network host -d --restart unless-stopped --name mema_mimic3 -v "${HOME}/.local/share/mycroft/mimic3:/home/mimic3/.local/share/mycroft/mimic3" 'mycroftai/mimic3'
docker run -d --network host -v node_red_data:/data --restart unless-stopped --name mema_nodered nodered/node-red

echo 'copying rough rhasspy profile to /root/.config/rhasspy/profiles/en'
cp rhasspy/profiles/en/profile.json /root/.config/rhasspy/profiles/en

echo '*-------------------------------------------------------------------------------*'
echo 'trying to start systemd servers'
systemctl daemon-reload
echo 'starting intent server'
systemctl start intent_server
echo 'starting face unlock server'
systemctl start unlock_server
echo '*-------------------------------------------------------------------------------*'
echo 'almost done!'
echo 'please install the binary for handlr at https://github.com/chmln/handlr'
echo 'trying to install the binary for jaro at https://github.com/isamert/jaro.git'
git clone https://github.com/isamert/jaro.git
cp jaro/jaro /usr/local/bin

echo 'rhasspy will need further set up at http://localhost:12101'
echo 'please reboot now'
exit 0
13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

23 changes: 23 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# note that some packages are supplied in install.sh via the packaging system
configobj
datetime
fastapi
pathlib
# only need replicate if using replicate.ai
replicate
sqlite3
time
webbrowser
wordcloud
gunicorn
uvicorn[standard]
paho-mqtt
imutils
face_recognition
dlib
pickle
# package?
opencv-python



Loading

0 comments on commit f98459d

Please sign in to comment.