Commit ed2d0796 authored by NilanDMeegoda's avatar NilanDMeegoda

attention_span_fix

parent cddc0e2a
......@@ -21,45 +21,50 @@ from controler import captureImage
from keras.models import load_model
from sklearn.preprocessing import OneHotEncoder
from datetime import datetime
# Attention classes
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(
['mkv', 'webm', 'mp4', 'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
x = datetime.datetime.now()
# Initializing flask app
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# for prediction
@app.route('/upload', methods=['POST'])
@cross_origin()
def predictAttention():
print(request)
target = os.path.join(UPLOAD_FOLDER, 'test_vids')
if not os.path.isdir(target):
os.mkdir(target)
directory = os.getcwd()
dataJson = []
file = request.files['file']
testNo = request.form.get('questionIndex')
filename = secure_filename("Testing_vid")
destination = "/".join([target, filename])
file.save(destination)
session['uploadFilePath'] = destination
filename = request.form.get('filename')
if file is None or filename == "":
return jsonify({'error: no file'})
file.save("./uploads/"+filename)
destination = directory + r"\uploads\att.mp4"
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({
"activityName": "Manual_Attention_Test",
"questionIndex": testNo,
"attentionLevelScore": scoreLst,
"attentionLevelScore": dataDict,
"createdAt":dt_string,
})
print("Prediction", scoreLst)
return scoreLst
print("Prediction02", scoreLst)
print("Prediction", dataDict)
return jsonify(dataJson)
@app.route('/parents/', methods=['POST', 'GET'])
......
This diff is collapsed.
......@@ -70,6 +70,7 @@ const AttentionSpan_screen = () => {
console.log("testing", blob);
const data = new FormData();
data.append("file", blob);
data.append("filename", "att.mp4")
data.append("questionIndex", id);
await API.post("upload", data, {
headers: {
......@@ -77,7 +78,8 @@ const AttentionSpan_screen = () => {
},
})
.then((res) => {
setattention(res.data);
console.log(res.data[0])
setattention(res.data[0]);
setisClicked(true);
})
.catch((err) => {
......@@ -221,15 +223,15 @@ const AttentionSpan_screen = () => {
<>
<p>
Low level attention :{" "}
{attention[0] * 100}
{Math.round(attention.low_attention* 100)/100}
</p>
<p>
Mid level attention :{" "}
{attention[1] * 100}
{attention.mid_attention * 100}
</p>
<p>
High level attention :{" "}
{attention[2] * 100}
{attention.high_attention * 100}
</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