Skip to content

Commit ff66d38

Browse files
committed
Added files with workflow dir
0 parents  commit ff66d38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1961
-0
lines changed

.github/workflows/main.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# workflow name.
2+
name: Deploy KWS web app to Heroku.
3+
4+
# Run workflow on every push to main branch.
5+
on:
6+
push:
7+
branches: [main]
8+
9+
# Workflows jobs.
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
# Check-out your repository.
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Build, Push and Release the KWS app as Docker container to Heroku.
19+
uses: gonuit/heroku-docker-deploy@v1.3.3 # GitHub action name (leave it as it is).
20+
with:
21+
email: ${{ secrets.HEROKU_EMAIL }}
22+
23+
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
24+
25+
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
26+
27+
# (Optional, default: "./")
28+
# Dockerfile directory
29+
dockerfile_directory: ./
30+
31+
# (Optional, default: "Dockerfile")
32+
# Dockerfile name
33+
dockerfile_name: Dockerfile
34+
35+
# (Optional, default: "")
36+
# Additional options of docker build command.
37+
docker_options: "--no-cache"
38+
39+
# (Optional, default: "web")
40+
# Select the process type for which you want the docker container to be uploaded.
41+
# By default, this argument is set to "web".
42+
# For more information look at https://devcenter.heroku.com/articles/process-model
43+
process_type: web

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__/

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.8
2+
3+
COPY . /app
4+
5+
WORKDIR /app
6+
7+
RUN pip install -r requirements.txt
8+
9+
EXPOSE $PORT
10+
11+
CMD gunicorn --workers=5 --bind 0.0.0.0:$PORT app:app

README.md

Lines changed: 214 additions & 0 deletions
Large diffs are not rendered by default.

app.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
@author: Jithin Sasikumar
5+
6+
Script to create a web application that wraps the trained model to be used for inference using `FLASK API`.
7+
It facilitates the application to run from a server which defines every routes and functions to perform.
8+
The front-end is designed using `./templates/page.html` and its styles in `./static/page.css`
9+
10+
Note:
11+
Make sure to define all the variables and valid paths in `.config_dir/config.yaml` to run this script
12+
without errors and issues.
13+
"""
14+
15+
from kws_spotter import SpeechRecognition
16+
from omegaconf import OmegaConf
17+
from src.data import check_fileType
18+
from src.exception_handler import NotFoundError
19+
from flask import Flask, render_template, request, redirect, flash, abort
20+
21+
app = Flask(__name__)
22+
app.config["SECRET_KEY"] = "MyKWSAppSecretKey"
23+
cfg = OmegaConf.load('./config_dir/config.yaml')
24+
25+
@app.route('/')
26+
def home():
27+
"""
28+
Returns the result of calling render_template() with page.html
29+
"""
30+
return render_template('page.html')
31+
32+
@app.route("/transcribe", methods = ["POST"])
33+
def transcribe():
34+
"""
35+
Returns the prediction from trained model artifact whenever transcribe route is called.
36+
It accepts file input (.wav) whenever user uploads the file, and make prediction using it.
37+
The `app.route()` decorator does the job of event handling by means of `jinja2` template
38+
engine.
39+
40+
Raises
41+
------
42+
NotFoundError: Exception
43+
404 error, if any exception occurs.
44+
"""
45+
46+
recognized_keyword = ""
47+
redirect(request.url)
48+
49+
if request.method == "POST":
50+
audio_file = request.files["file"]
51+
if audio_file.filename == "":
52+
flash("File not found !!!", category="error")
53+
return render_template("page.html")
54+
55+
elif not check_fileType(filename=audio_file.filename, extension=".wav"):
56+
flash(f"Unsupported file format. Please use only .wav files", category="error")
57+
return render_template("page.html")
58+
59+
else:
60+
try:
61+
recognizer = SpeechRecognition(audio_file,
62+
cfg.paths.model_artifactory_dir,
63+
cfg.params.n_mfcc,
64+
cfg.params.mfcc_length,
65+
cfg.params.sampling_rate)
66+
recognized_keyword, label_probability = recognizer.predict()
67+
68+
except NotFoundError:
69+
abort(404, description = "Sorry, something went wrong. Cannot predict from the model. Please try again !!!")
70+
71+
return render_template(
72+
"page.html",
73+
recognized_keyword = f"Transcribed keyword: {recognized_keyword.title()}",
74+
label_probability = f"Predicted probability: {label_probability}"
75+
)
76+
77+
if __name__ == "__main__":
78+
app.run(debug=False)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
artifact_uri: file:/./artifacts/2/asr_model_1.3/model_artifacts
2+
end_time: 1659924195701
3+
entry_point_name: ''
4+
experiment_id: '2'
5+
lifecycle_stage: active
6+
name: ''
7+
run_name: asr_model_1.3
8+
run_id: 95d1e7e807f94e5aaacf87d19a193437
9+
run_uuid: 95d1e7e807f94e5aaacf87d19a193437
10+
source_name: ''
11+
source_type: 4
12+
source_version: ''
13+
start_time: 1659922818963
14+
status: 3
15+
tags: []
16+
user_id: Jithin Sasikumar
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
1659922842560 0.2367211878299713 0
2+
1659922856734 0.47320428490638733 1
3+
1659922870169 0.5671737790107727 2
4+
1659922882720 0.6185272336006165 3
5+
1659922895481 0.6531676054000854 4
6+
1659922908735 0.6832131147384644 5
7+
1659922921794 0.7047829627990723 6
8+
1659922934851 0.7211627960205078 7
9+
1659922947979 0.7300192713737488 8
10+
1659922961468 0.7410184741020203 9
11+
1659922975200 0.7506606578826904 10
12+
1659922988485 0.7617074847221375 11
13+
1659923003326 0.7688260078430176 12
14+
1659923016847 0.7739923596382141 13
15+
1659923030232 0.7799919247627258 14
16+
1659923045841 0.7842296957969666 15
17+
1659923059265 0.7891340851783752 16
18+
1659923072493 0.793633759021759 17
19+
1659923085672 0.7991334199905396 18
20+
1659923098834 0.8038473725318909 19
21+
1659923112143 0.8079898953437805 20
22+
1659923125263 0.8112039566040039 21
23+
1659923138584 0.8136799931526184 22
24+
1659923151989 0.8179653882980347 23
25+
1659923165266 0.8211794495582581 24
26+
1659923178445 0.8254410624504089 25
27+
1659923191541 0.8261076807975769 26
28+
1659923204868 0.8320834040641785 27
29+
1659923217563 0.830869197845459 28
30+
1659923230182 0.8335832953453064 29
31+
1659923242999 0.835821270942688 30
32+
1659923255703 0.8387972116470337 31
33+
1659923268434 0.8411542177200317 32
34+
1659923280973 0.8432493209838867 33
35+
1659923293571 0.845272958278656 34
36+
1659923306199 0.8477251529693604 35
37+
1659923319272 0.8485584259033203 36
38+
1659923331955 0.8484393954277039 37
39+
1659923344778 0.8536056876182556 38
40+
1659923357498 0.8547008633613586 39
41+
1659923370517 0.8546056151390076 40
42+
1659923383387 0.856986403465271 41
43+
1659923396165 0.8616051077842712 42
44+
1659923408770 0.8624145984649658 43
45+
1659923422330 0.8639144897460938 44
46+
1659923435852 0.8649381995201111 45
47+
1659923449786 0.8659143447875977 46
48+
1659923467001 0.8686284422874451 47
49+
1659923480796 0.8686760663986206 48
50+
1659923494258 0.8707473278045654 49
51+
1659923507263 0.8679141998291016 50
52+
1659923520845 0.872890055179596 51
53+
1659923533544 0.8757231831550598 52
54+
1659923546638 0.8804371356964111 53
55+
1659923561649 0.8781277537345886 54
56+
1659923575204 0.8783896565437317 55
57+
1659923588283 0.878484845161438 56
58+
1659923601433 0.882603645324707 57
59+
1659923616277 0.8835559487342834 58
60+
1659923629571 0.8823893666267395 59
61+
1659923645847 0.8875318169593811 60
62+
1659923659438 0.8853177428245544 61
63+
1659923672834 0.8878889679908752 62
64+
1659923686228 0.8853177428245544 63
65+
1659923699485 0.8881984353065491 64
66+
1659923713295 0.8882222771644592 65
67+
1659923726375 0.8909125328063965 66
68+
1659923739922 0.8898174166679382 67
69+
1659923753805 0.8918410539627075 68
70+
1659923767717 0.8929838538169861 69
71+
1659923781480 0.8965073823928833 70
72+
1659923794483 0.8933409452438354 71
73+
1659923808193 0.8966740369796753 72
74+
1659923821514 0.8954598307609558 73
75+
1659923834565 0.8966264128684998 74
76+
1659923848253 0.8974120616912842 75
77+
1659923862007 0.8988405466079712 76
78+
1659923875662 0.9000785946846008 77
79+
1659923889053 0.8966264128684998 78
80+
1659923902065 0.9010546803474426 79
81+
1659923915165 0.9033164381980896 80
82+
1659923928654 0.9027450680732727 81
83+
1659923942307 0.9036497473716736 82
84+
1659923955941 0.9023165106773376 83
85+
1659923969885 0.9063400030136108 84
86+
1659923983019 0.905768632888794 85
87+
1659923996770 0.9074113965034485 86
88+
1659924010476 0.9073875546455383 87
89+
1659924024028 0.9051734209060669 88
90+
1659924038079 0.9078398942947388 89
91+
1659924052175 0.9101016521453857 90
92+
1659924065742 0.9077208638191223 91
93+
1659924079219 0.9108873009681702 92
94+
1659924092400 0.9098397493362427 93
95+
1659924105249 0.9121491312980652 94
96+
1659924118414 0.9109587669372559 95
97+
1659924131536 0.9114587306976318 96
98+
1659924144540 0.9124110341072083 97
99+
1659924157553 0.9134347438812256 98
100+
1659924170923 0.9148393869400024 99
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
1659922842560 2.4952046871185303 0
2+
1659922856734 1.716299295425415 1
3+
1659922870169 1.4166145324707031 2
4+
1659922882720 1.248712182044983 3
5+
1659922895481 1.1427977085113525 4
6+
1659922908735 1.0426537990570068 5
7+
1659922921794 0.9818977117538452 6
8+
1659922934851 0.9291539788246155 7
9+
1659922947979 0.895833432674408 8
10+
1659922961468 0.8596310019493103 9
11+
1659922975200 0.8265460729598999 10
12+
1659922988485 0.8000710010528564 11
13+
1659923003326 0.7689289450645447 12
14+
1659923016847 0.7536243796348572 13
15+
1659923030232 0.7343848347663879 14
16+
1659923045841 0.7132591009140015 15
17+
1659923059265 0.7008107900619507 16
18+
1659923072493 0.678989589214325 17
19+
1659923085672 0.6663210391998291 18
20+
1659923098834 0.6497147083282471 19
21+
1659923112143 0.634120762348175 20
22+
1659923125263 0.6239477396011353 21
23+
1659923138584 0.6174495220184326 22
24+
1659923151989 0.5989447832107544 23
25+
1659923165266 0.5913788676261902 24
26+
1659923178445 0.5787534713745117 25
27+
1659923191541 0.5735382437705994 26
28+
1659923204868 0.5526419878005981 27
29+
1659923217563 0.5552822947502136 28
30+
1659923230182 0.5471318960189819 29
31+
1659923242999 0.5350935459136963 30
32+
1659923255703 0.5209813117980957 31
33+
1659923268434 0.5235905051231384 32
34+
1659923280973 0.5151183605194092 33
35+
1659923293571 0.5096074938774109 34
36+
1659923306199 0.5014923214912415 35
37+
1659923319272 0.500800371170044 36
38+
1659923331955 0.4889707565307617 37
39+
1659923344778 0.4835958480834961 38
40+
1659923357498 0.47962528467178345 39
41+
1659923370517 0.4711167812347412 40
42+
1659923383387 0.4738617539405823 41
43+
1659923396165 0.46255970001220703 42
44+
1659923408770 0.45413967967033386 43
45+
1659923422330 0.4463930130004883 44
46+
1659923435852 0.44139787554740906 45
47+
1659923449786 0.4404941201210022 46
48+
1659923467001 0.4346374273300171 47
49+
1659923480796 0.42682474851608276 48
50+
1659923494258 0.42316028475761414 49
51+
1659923507263 0.4273654818534851 50
52+
1659923520845 0.4158058762550354 51
53+
1659923533544 0.4054386615753174 52
54+
1659923546638 0.39449623227119446 53
55+
1659923561649 0.3974525034427643 54
56+
1659923575204 0.3968679904937744 55
57+
1659923588283 0.3926546573638916 56
58+
1659923601433 0.3866346776485443 57
59+
1659923616277 0.3816819489002228 58
60+
1659923629571 0.3816310465335846 59
61+
1659923645847 0.36722272634506226 60
62+
1659923659438 0.37166881561279297 61
63+
1659923672834 0.3685093820095062 62
64+
1659923686228 0.37123700976371765 63
65+
1659923699485 0.36265233159065247 64
66+
1659923713295 0.36106783151626587 65
67+
1659923726375 0.35437360405921936 66
68+
1659923739922 0.35571980476379395 67
69+
1659923753805 0.35591378808021545 68
70+
1659923767717 0.3518858551979065 69
71+
1659923781480 0.3426003158092499 70
72+
1659923794483 0.3497261703014374 71
73+
1659923808193 0.3405553698539734 72
74+
1659923821514 0.3353274166584015 73
75+
1659923834565 0.33460214734077454 74
76+
1659923848253 0.33476415276527405 75
77+
1659923862007 0.3266696333885193 76
78+
1659923875662 0.32614389061927795 77
79+
1659923889053 0.33459004759788513 78
80+
1659923902065 0.32729673385620117 79
81+
1659923915165 0.3177652359008789 80
82+
1659923928654 0.3186085522174835 81
83+
1659923942307 0.3136427402496338 82
84+
1659923955941 0.3173014521598816 83
85+
1659923969885 0.30845797061920166 84
86+
1659923983019 0.3082858920097351 85
87+
1659923996770 0.30485138297080994 86
88+
1659924010476 0.3031129837036133 87
89+
1659924024028 0.3045436441898346 88
90+
1659924038079 0.30047401785850525 89
91+
1659924052175 0.2946811318397522 90
92+
1659924065742 0.29913094639778137 91
93+
1659924079219 0.2920873463153839 92
94+
1659924092400 0.2959277033805847 93
95+
1659924105249 0.2898596525192261 94
96+
1659924118414 0.29318347573280334 95
97+
1659924131536 0.2892695367336273 96
98+
1659924144540 0.28708887100219727 97
99+
1659924157553 0.2843433618545532 98
100+
1659924170923 0.27645641565322876 99

0 commit comments

Comments
 (0)