Commit ed2d0796 authored by NilanDMeegoda's avatar NilanDMeegoda

attention_span_fix

parent cddc0e2a
Babsl-py==1.2.0 Babsl-py==1.2.0
......
...@@ -21,45 +21,50 @@ from controler import captureImage ...@@ -21,45 +21,50 @@ from controler import captureImage
from keras.models import load_model from keras.models import load_model
from sklearn.preprocessing import OneHotEncoder from sklearn.preprocessing import OneHotEncoder
from datetime import datetime
# Attention classes # Attention classes
attClass = {0: 'Low Attention', 1: 'Mid Attention', 2: 'High Attention'} attClass = {0: 'Low Attention', 1: 'Mid Attention', 2: 'High Attention'}
UPLOAD_FOLDER = 'C:/SLIIT/Final Research implementation/Backend/new model 2.0/Main Project code/uploads'
ALLOWED_EXTENSIONS = set( ALLOWED_EXTENSIONS = set(
['mkv', 'webm', 'mp4', 'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) ['mkv', 'webm', 'mp4', 'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
x = datetime.datetime.now()
# Initializing flask app # Initializing flask app
app = Flask(__name__) app = Flask(__name__)
cors = CORS(app) cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type' app.config['CORS_HEADERS'] = 'Content-Type'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# for prediction # for prediction
@app.route('/upload', methods=['POST']) @app.route('/upload', methods=['POST'])
@cross_origin()
def predictAttention(): def predictAttention():
print(request) print(request)
target = os.path.join(UPLOAD_FOLDER, 'test_vids') directory = os.getcwd()
if not os.path.isdir(target): dataJson = []
os.mkdir(target)
file = request.files['file'] file = request.files['file']
testNo = request.form.get('questionIndex') testNo = request.form.get('questionIndex')
filename = secure_filename("Testing_vid") filename = request.form.get('filename')
destination = "/".join([target, filename]) if file is None or filename == "":
file.save(destination) return jsonify({'error: no file'})
session['uploadFilePath'] = destination file.save("./uploads/"+filename)
destination = directory + r"\uploads\att.mp4"
scoreLst = captureImage(destination, 10) scoreLst = captureImage(destination, 10)
dataDict = {
'low_attention': scoreLst[0],
'mid_attention': scoreLst[1],
'high_attention': scoreLst[2],
}
dataJson.append(dataDict)
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
db.db['attentionlevelScore'].insert_one({ db.db['attentionlevelScore'].insert_one({
"activityName": "Manual_Attention_Test", "activityName": "Manual_Attention_Test",
"questionIndex": testNo, "questionIndex": testNo,
"attentionLevelScore": scoreLst, "attentionLevelScore": dataDict,
"createdAt":dt_string,
}) })
print("Prediction", scoreLst) print("Prediction02", scoreLst)
return scoreLst print("Prediction", dataDict)
return jsonify(dataJson)
@app.route('/parents/', methods=['POST', 'GET']) @app.route('/parents/', methods=['POST', 'GET'])
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -70,6 +70,7 @@ const AttentionSpan_screen = () => { ...@@ -70,6 +70,7 @@ const AttentionSpan_screen = () => {
console.log("testing", blob); console.log("testing", blob);
const data = new FormData(); const data = new FormData();
data.append("file", blob); data.append("file", blob);
data.append("filename", "att.mp4")
data.append("questionIndex", id); data.append("questionIndex", id);
await API.post("upload", data, { await API.post("upload", data, {
headers: { headers: {
...@@ -77,7 +78,8 @@ const AttentionSpan_screen = () => { ...@@ -77,7 +78,8 @@ const AttentionSpan_screen = () => {
}, },
}) })
.then((res) => { .then((res) => {
setattention(res.data); console.log(res.data[0])
setattention(res.data[0]);
setisClicked(true); setisClicked(true);
}) })
.catch((err) => { .catch((err) => {
...@@ -221,15 +223,15 @@ const AttentionSpan_screen = () => { ...@@ -221,15 +223,15 @@ const AttentionSpan_screen = () => {
<> <>
<p> <p>
Low level attention :{" "} Low level attention :{" "}
{attention[0] * 100} {Math.round(attention.low_attention* 100)/100}
</p> </p>
<p> <p>
Mid level attention :{" "} Mid level attention :{" "}
{attention[1] * 100} {attention.mid_attention * 100}
</p> </p>
<p> <p>
High level attention :{" "} High level attention :{" "}
{attention[2] * 100} {attention.high_attention * 100}
</p> </p>
</> </>
)} )}
......
{
"lockfileVersion": 1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment