From 0dc0dde267a1508df1f60909cc09313f909d821b Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 24 Feb 2019 21:46:11 -0500 Subject: [PATCH] Using /share for persistance of snowboy/precise models --- mycroft-precise/app.py | 18 +++++++++++------- mycroft-precise/config.json | 5 +++-- snowboy/README.md | 2 +- snowboy/app.py | 18 +++++++++++------- snowboy/config.json | 3 ++- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/mycroft-precise/app.py b/mycroft-precise/app.py index 5e4ff36..172f3dc 100644 --- a/mycroft-precise/app.py +++ b/mycroft-precise/app.py @@ -2,31 +2,35 @@ import json from uuid import uuid4 -from flask import Flask, request, send_file, render_template +from flask import Flask, request, send_file, render_template, safe_join app = Flask('mycroft-precise', template_folder='.') app.secret_key = str(uuid4()) config_path = os.environ.get('CONFIG_PATH', '/data/options.json') -model_path = os.environ.get('MODEL_PATH', '/models') +models_dir = os.environ.get('MODEL_PATH', '/share/precise') @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': if 'delete' in request.form: model_name = request.form['model'] - os.unlink(os.path.join(model_path, model_name)) + model_path = safe_join(models_dir, model_name) + if os.path.exists(model_path): + os.unlink(model_path) elif 'file' in request.files: file = request.files['file'] model_name = file.filename - file.save(os.path.join(model_path, model_name)) + model_path = safe_join(models_dir, model_name) + os.makedirs(models_dir, exist_ok=True) + file.save(model_path) with open(config_path, 'r') as config_file: config = json.load(config_file) models = [] - if os.path.exists(model_path): - for model_name in os.listdir(model_path): - models.append(os.path.join(model_path, model_name)) + if os.path.exists(models_dir): + for model_name in os.listdir(models_dir): + models.append(os.path.join(models_dir, model_name)) return render_template('index.html', config=config, models=models) diff --git a/mycroft-precise/config.json b/mycroft-precise/config.json index ed5011a..586168b 100644 --- a/mycroft-precise/config.json +++ b/mycroft-precise/config.json @@ -1,10 +1,11 @@ { "name": "Mycroft Precise Wake System for Rhasspy", "slug": "precise-rhasspy", - "version": "0.2.0-2", + "version": "0.2.0-3", "description": "Mycroft Precise wake word detection (Mycroft.ai) for Rhasspy voice assistant", "startup": "application", "boot": "auto", + "map": ["share:rw"], "options": { "host": "localhost", "port": 1883, @@ -13,7 +14,7 @@ "reconnect": 5, "site_id": "default", "wakeword_id": "default", - "model": "/models/okay-rhasspy.pb", + "model": "/share/precise/okay-rhasspy.pb", "sensitivity": 0.5, "trigger_level": 3 }, diff --git a/snowboy/README.md b/snowboy/README.md index 66b075c..23cb818 100644 --- a/snowboy/README.md +++ b/snowboy/README.md @@ -2,7 +2,7 @@ Snowboy Wake Listener ========================= Small service that listens for a wake word with [snowboy](https://snowboy.kitt.ai). -Audio data is streamed in from [Rhasspy](https://github.com/synesthesiam/rhasspy-hassio-addon) via [MQTT](http://mqtt.org/). +Audio data is streamed in from [Rhasspy](https://github.com/synesthesiam/rhasspy) via [MQTT](http://mqtt.org/). Building diff --git a/snowboy/app.py b/snowboy/app.py index 5e4ff36..f2eb600 100644 --- a/snowboy/app.py +++ b/snowboy/app.py @@ -2,31 +2,35 @@ import json from uuid import uuid4 -from flask import Flask, request, send_file, render_template +from flask import Flask, request, send_file, render_template, safe_join app = Flask('mycroft-precise', template_folder='.') app.secret_key = str(uuid4()) config_path = os.environ.get('CONFIG_PATH', '/data/options.json') -model_path = os.environ.get('MODEL_PATH', '/models') +models_dir = os.environ.get('MODEL_PATH', '/share/snowboy') @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': if 'delete' in request.form: model_name = request.form['model'] - os.unlink(os.path.join(model_path, model_name)) + model_path = safe_join(models_dir, model_name) + if os.path.exists(model_path): + os.unlink(model_path) elif 'file' in request.files: file = request.files['file'] model_name = file.filename - file.save(os.path.join(model_path, model_name)) + model_path = safe_join(models_dir, model_name) + os.makedirs(models_dir, exist_ok=True) + file.save(model_path) with open(config_path, 'r') as config_file: config = json.load(config_file) models = [] - if os.path.exists(model_path): - for model_name in os.listdir(model_path): - models.append(os.path.join(model_path, model_name)) + if os.path.exists(models_dir): + for model_name in os.listdir(models_dir): + models.append(os.path.join(models_dir, model_name)) return render_template('index.html', config=config, models=models) diff --git a/snowboy/config.json b/snowboy/config.json index 14aa6be..95b35d7 100644 --- a/snowboy/config.json +++ b/snowboy/config.json @@ -1,10 +1,11 @@ { "name": "Snowboy Wake System for Rhasspy", "slug": "snowboy-rhasspy", - "version": "1.3.0-1", + "version": "1.3.0-2", "description": "Snowboy wake word detection (Kitt.ai) for Rhasspy voice assistant", "startup": "application", "boot": "auto", + "map": ["share:rw"], "options": { "host": "localhost", "port": 1883,