Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
56df350
started Acoustic modelling
Stella-Mutacho Jun 1, 2022
5cdc303
First run on acoustic modelling
Stella-Mutacho Jun 2, 2022
39d754a
speech recognition start file
hewanm Jun 2, 2022
deb1a71
Corrected amharic characters for training
Stella-Mutacho Jun 2, 2022
d036b37
exploration on the swahili dataset and began acoustic modelling
Stella-Mutacho Jun 2, 2022
ab16f4b
working on speech recognition
Jun 3, 2022
e3d5ef0
working on speech recognition
Jun 3, 2022
369b467
working on speech recognition
Jun 3, 2022
bf4c0ec
working on speech recognition
Jun 3, 2022
c88fb14
Completed acoustic modelling on the Amharic dataset
Stella-Mutacho Jun 3, 2022
272da45
Final modelling notebook on the Amahric dataset
Stella-Mutacho Jun 3, 2022
ea7c2f4
feat: add prediction endpoint
nahomfix Jun 3, 2022
209d899
frontend react setup
hewanm Jun 3, 2022
517b2c2
editing app js file
Jun 4, 2022
bcb20ff
Create Another backend file
ProgrammingOperative Jun 5, 2022
42c1329
Initialze flask app
ProgrammingOperative Jun 5, 2022
66014f5
Add prediction file
ProgrammingOperative Jun 5, 2022
d1f3507
Create a DB and schema
ProgrammingOperative Jun 5, 2022
5d20f68
Create and Initialize DB
ProgrammingOperative Jun 5, 2022
7a89433
Test received json
ProgrammingOperative Jun 5, 2022
bba29d3
API able to receive json
ProgrammingOperative Jun 6, 2022
9209b1c
Combine api files
ProgrammingOperative Jun 6, 2022
13380c0
Create dictionary to be served by model
ProgrammingOperative Jun 6, 2022
c7d404b
Test Server
ProgrammingOperative Jun 6, 2022
159543d
Try prediction
ProgrammingOperative Jun 6, 2022
3b71f47
Add backend scripts
ProgrammingOperative Jun 6, 2022
a9b0616
Audio Upload draft
hewanm Jun 7, 2022
2c5c12f
Merge https://github.com/week4-SpeechRecognition/Speech-to-Text into …
hewanm Jun 7, 2022
8aaaf11
modifiying app js
Jun 7, 2022
5c5c213
upload audio
hewanm Jun 7, 2022
6e0dbe3
upload audio
hewanm Jun 7, 2022
e5d1696
upload audio
hewanm Jun 7, 2022
ae48202
upload audio
hewanm Jun 8, 2022
769a364
upload audio fix
hewanm Jun 8, 2022
6e74921
upload audio fix
hewanm Jun 8, 2022
f4a681a
updating the audio record file
Jun 8, 2022
06d081a
working with the speech record
Jun 9, 2022
fd87808
UI
hewanm Jun 9, 2022
011e595
Conflict resolved
hewanm Jun 9, 2022
d90df89
editing the app js
Jun 9, 2022
ebaa6f1
adding homepage
Jun 9, 2022
01b4f40
adding routes to app js
Jun 9, 2022
b6a2114
Conflict resolved
hewanm Jun 9, 2022
5b84f15
Merge branch 'frontend' of https://github.com/week4-SpeechRecognition…
hewanm Jun 9, 2022
3b03665
updating the page
Jun 9, 2022
2c0f5b5
home page
hewanm Jun 9, 2022
997e5f6
Merge branch 'frontend' of https://github.com/week4-SpeechRecognition…
hewanm Jun 9, 2022
e96b654
wip: start model integration in api
nahomfix Jun 9, 2022
6752fb6
upload
hewanm Jun 9, 2022
4a4bb13
design improvement
hewanm Jun 9, 2022
1de1bf1
design improvement
hewanm Jun 9, 2022
fba5136
design improvement
hewanm Jun 9, 2022
0b79b7f
chore: delete unnecessary files
nahomfix Jun 9, 2022
0263043
chore: add dashboard screen capture
nahomfix Jun 9, 2022
0b1b548
fix: connect dashboard buttons
nahomfix Jun 9, 2022
bf05aba
fix: api prediction fix
nahomfix Jun 9, 2022
b2f2445
Merge pull request #33 from week4-SpeechRecognition/backend
nahomfix Jun 9, 2022
0783daa
chore: integrate frontend and backend
nahomfix Jun 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dmypy.json

# Pyre type checker
.pyre/

#node modules
node_modules/
91 changes: 91 additions & 0 deletions backend/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import sys
from datetime import datetime
from pathlib import Path

import pandas as pd
from flask import Flask, jsonify, make_response, request
from flask_cors import CORS

sys.path.append("../")
from scripts.helpers import *
from scripts.logspectrogram import *
from scripts.models import *
from scripts.predict import *
from scripts.tokenizer import *

# load files
meta_data = pd.read_csv("../data/backend_data/meta_data.csv")
sorted_metadata = meta_data.sort_values(by="duration")
labels = sorted_metadata["label"].to_list()
translation_obj = read_obj("../data/backend_data/translation_dict.pkl")

# load translation
translations = []
for label in labels:
translations.append(translation_obj[label])

# init tokenizer
tokenizer = Tokenizer(translations)
int_to_char, char_to_int = tokenizer.build_dict()
output_dim = len(char_to_int) + 2

# CNN
n_mels = 128
cnn_model, cnn_shape = cnn_net(n_mels)

# BI-DIRECTIONAL RNN
batch_size = 32
bi_rnn = bi_directional_rnn(1024, batch_size=batch_size, output_dim=output_dim)

# preprocessor
sample_rate = 8000
fft_size = 512
frame_step = 256

preprocess_model = preprocess_model(sample_rate, fft_size, frame_step, n_mels)

# build model
cnn_bi_rnn_model = build_model(output_dim, cnn_model, bi_rnn, preprocess_model)

# load saved model
cnn_bi_rnn_model.load_weights("../model/cnn-bi-rnn.h5")


app = Flask(__name__)
CORS(app)


@app.route("/health", methods=["GET"])
def health():
return make_response(
jsonify(
{
"success": True,
"timestamp": datetime.now().isoformat(),
}
),
200,
)


@app.route("/predict", methods=["POST"])
def predict_audio():
file = request.files["file"]

# preprocess audio
extracted_audio = extract_audio(file)

# predict
predicted, error = predict(
cnn_bi_rnn_model,
extracted_audio,
tokenizer,
int_to_char,
actual=None,
)

return make_response(jsonify({"success": True, "data": predicted}), 200)


if __name__ == "__main__":
app.run(host="localhost", port=5000, debug=False)
Binary file added backend/db.sqlite
Binary file not shown.
91 changes: 91 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
import sys

import pandas as pd
from fastapi import FastAPI, UploadFile

sys.path.append("../")
from scripts.helpers import *
from scripts.logspectrogram import *
from scripts.models import *
from scripts.predict import *
from scripts.tokenizer import *

# load files
meta_data = pd.read_csv("../data/backend_data/meta_data.csv")
sorted_metadata = meta_data.sort_values(by="duration")
labels = sorted_metadata["label"].to_list()
translation_obj = read_obj("../data/backend_data/translation_dict.pkl")

# load translation
translations = []
for label in labels:
translations.append(translation_obj[label])

# init tokenizer
tokenizer = Tokenizer(translations)
int_to_char, char_to_int = tokenizer.build_dict()
output_dim = len(char_to_int) + 2

# CNN
n_mels = 128
cnn_model, cnn_shape = cnn_net(n_mels)

# BI-DIRECTIONAL RNN
batch_size = 32
bi_rnn = bi_directional_rnn(1024, batch_size=batch_size, output_dim=output_dim)

# preprocessor
sample_rate = 8000
fft_size = 512
frame_step = 256

preprocessing_model = preprocess_model(
sample_rate, fft_size, frame_step, n_mels
)

# build model
cnn_bi_rnn_model = build_model(
output_dim, cnn_model, bi_rnn, preprocessing_model
)

# load saved model
cnn_bi_rnn_model.load_weights("../model/cnn-bi-rnn.h5")

app = FastAPI()


@app.get("/")
async def index():
return {"status": 200, "message": "Server Works"}


@app.post("/type")
async def get_type(file: UploadFile):
return {
"type": file.content_type,
}


@app.post("/predict")
async def predict_audio(file: UploadFile):
if file.content_type == "audio/wave":
# load data from request
audio_file = file.file

# preprocess audio
extracted_audio = extract_audio(audio_file)

# predict
predicted, error = predict(
cnn_bi_rnn_model,
extracted_audio[0],
tokenizer,
int_to_char,
actual=None,
)
# build response
return {"predicted": predicted}

else:
return {"Status": False, "Message": "Unsupported file type"}
75 changes: 75 additions & 0 deletions backend/titus_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from distutils.log import debug
from datetime import datetime
from pickle import load
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow

from flask import Flask, jsonify, make_response, request
import os


#Initialize App
app = Flask(__name__)

base_dir = os.path.dirname(__file__)

#Database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(base_dir, 'db.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

#Init DB
db = SQLAlchemy(app)

#Init Marshmallow
ma = Marshmallow(app)

# Creating the features db
class Features(db.Model):
id = db.Column(db.Integer, primary_key=True)
path = db.Column(db.String(200))
text = db.Column(db.String(1000))
duration = db.Column(db.String(250))

def __init__(self, path,text, duration):
self.path = path
self.text = text
self.duration = duration


#Create the database schema
class FeatureSchema(ma.Schema):
class Meta:
fields = ['id', 'path', 'text', 'duration']

#Init Schema
feature_schema = FeatureSchema()
# products_schema = ProductSchema(many=True,)


#Route to handle the prediction
@app.route('/predict', methods=['POST', 'GET'])
def predict():
#Filtering details from received json file and processing

path = request.json['path']
text = request.json['text']
duration = request.json['duration']

new_file = Features(path,text, duration)
db.session.add(new_file)
db.session.commit()

file = {"path": path,
"text": text,
"duration": duration}

# pwd = os.getcwd()
# rnn_model_path = os.path.join(pwd, "../model/RNN_model.pickle")
# rnn_model = load(open(rnn_model_path, "rb"))
# prediction = rnn_model.predict(file)

return jsonify(file)


if __name__ == '__main__':
app.run(debug=True)
45 changes: 45 additions & 0 deletions backend/titus_nahom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from datetime import datetime
from pickle import load

from flask import Flask, jsonify, make_response, request

app = Flask(__name__)


@app.route("/health", methods=["GET"])
def health():
return make_response(
jsonify(
{
"success": True,
"timestamp": datetime.now().isoformat(),
}
),
200,
)


@app.route("/predict", methods=["POST", 'GET'])
def predict():
path = request.json['path']
text = request.json['text']
duration = request.json['duration']

#Assemble files to form a new dictionary
file = {"path": path,
"text": text,
"duration": duration}

pwd = os.getcwd()
rnn_model_path = os.path.join(pwd, "../model/RNN_model.pickle")
rnn_model = load(open(rnn_model_path, "rb"))
prediction = rnn_model.predict(file)

return jsonify(file)

return make_response(jsonify({"success": True, "data": prediction}), 200)


if __name__ == "__main__":
app.run(host="localhost", port=5000, debug=True)
Loading