Skip to content

Commit

Permalink
Added basic web interface for snowboy, precise addons
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Jan 12, 2019
1 parent cfc298c commit 3db3e3c
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
4 changes: 3 additions & 1 deletion mycroft-precise/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt-get update && apt-get install -y python3-dev build-essential \
jq libnanomsg-dev

RUN pip3 install --no-cache-dir wheel
RUN pip3 install --no-cache-dir flask
COPY etc/nanomsg-python-master.zip /

# Install nanomsg
Expand All @@ -29,7 +30,8 @@ COPY src/precise/scripts/listen.py /usr/lib/python3.6/site-packages/precise/scri

# Copy my stuff
COPY models /models
COPY main.py /
COPY *.py /
COPY *.html /
COPY run.sh /

ENTRYPOINT ["/run.sh"]
32 changes: 32 additions & 0 deletions mycroft-precise/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import json
from uuid import uuid4

from flask import Flask, request, send_file, render_template

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')

@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))
elif 'file' in request.files:
file = request.files['file']
model_name = file.filename
file.save(os.path.join(model_path, model_name))

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))

return render_template('index.html', config=config, models=models)
6 changes: 5 additions & 1 deletion mycroft-precise/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
"sensitivity": 0.5,
"trigger_level": 3
},
"ports": {
"12103/tcp": 12103
},
"schema": {
"model": "str",
"sensitivity": "float",
"trigger_level": "int",
"pub_address": "str",
"pull_address": "str"
}
},
"webui": "http://[HOST]:[PORT:12103]/"
}
52 changes: 52 additions & 0 deletions mycroft-precise/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<title>Mycroft Precise (Rhasspy)</title>
</head>
<body>
<h1>Mycroft Precise for Rhasspy</h1>
<p>
Wake word detection for the <a href="https://github.com/synesthesiam/rhasspy-hassio-addon/">Rhasspy voice assistant</a> with <a href="https://github.com/MycroftAI/mycroft-precise">Mycroft Precise</a>.
</p>

<hr>

<h2>Models</h2>
<form method="post" action="/" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload Model">
</form>
<br>

<form method="post" action="/" onsubmit="return confirm('Are you sure?');">
<input type="hidden" name="delete" value="1">
<table>
<thead>
<th>Model</th>
<th></th>
</thead>
<tbody>
{% for model in models %}
<tr>
<td>{{ model }}</td>
<td>
<button type="submit" name="model" value="{{ model }}">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>

<hr>

<h2>Configuration</h2>
<p>
{{ config }}
</p>
</body>
</html>
1 change: 1 addition & 0 deletions mycroft-precise/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sensitivity="$(jq --raw-output '.sensitivity' $CONFIG_PATH)"
trigger_level="$(jq --raw-output '.trigger_level' $CONFIG_PATH)"

cd "$DIR"
FLASK_APP=app.py flask run --host=0.0.0.0 --port=12103 &
python3 main.py \
--pub-address "$pub_address" \
--pull-address "$pull_address" \
Expand Down
5 changes: 4 additions & 1 deletion snowboy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ COPY snowboy-1.3.0.tar.gz /
COPY nanomsg-python-master.zip /

RUN pip3 install --no-cache-dir wheel
RUN pip3 install --no-cache-dir flask
RUN pip3 install --no-cache-dir /snowboy-1.3.0.tar.gz
RUN pip3 install --no-cache-dir /nanomsg-python-master.zip

COPY main.py /
COPY models/ /models
COPY *.py /
COPY *.html /
COPY run.sh /
ENTRYPOINT ["/run.sh"]
32 changes: 32 additions & 0 deletions snowboy/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import json
from uuid import uuid4

from flask import Flask, request, send_file, render_template

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')

@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))
elif 'file' in request.files:
file = request.files['file']
model_name = file.filename
file.save(os.path.join(model_path, model_name))

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))

return render_template('index.html', config=config, models=models)
6 changes: 5 additions & 1 deletion snowboy/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
"sensitivity": 0.5,
"audio_gain": 1.0
},
"ports": {
"12102/tcp": 12102
},
"schema": {
"model": "str",
"sensitivity": "float",
"audio_gain": "float",
"pub_address": "str",
"pull_address": "str"
}
},
"webui": "http://[HOST]:[PORT:12102]/"
}
52 changes: 52 additions & 0 deletions snowboy/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<title>Snowboy (Rhasspy)</title>
</head>
<body>
<h1>Snowboy for Rhasspy</h1>
<p>
Wake word detection for the <a href="https://github.com/synesthesiam/rhasspy-hassio-addon/">Rhasspy voice assistant</a> with <a href="https://snowboy.kitt.ai/">Snowboy</a>.
</p>

<hr>

<h2>Models</h2>
<form method="post" action="/" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload Model">
</form>
<br>

<form method="post" action="/" onsubmit="return confirm('Are you sure?');">
<input type="hidden" name="delete" value="1">
<table>
<thead>
<th>Model</th>
<th></th>
</thead>
<tbody>
{% for model in models %}
<tr>
<td>{{ model }}</td>
<td>
<button type="submit" name="model" value="{{ model }}">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>

<hr>

<h2>Configuration</h2>
<p>
{{ config }}
</p>
</body>
</html>
Binary file added snowboy/models/okay_rhasspy.pmdl
Binary file not shown.
Binary file added snowboy/models/snowboy.umdl
Binary file not shown.
1 change: 1 addition & 0 deletions snowboy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sensitivity="$(jq --raw-output '.sensitivity' $CONFIG_PATH)"
audio_gain="$(jq --raw-output '.audio_gain' $CONFIG_PATH)"

cd "$DIR"
FLASK_APP=app.py flask run --host=0.0.0.0 --port=12102 &
python3 main.py \
--pub-address "$pub_address" \
--pull-address "$pull_address" \
Expand Down

0 comments on commit 3db3e3c

Please sign in to comment.