Commit efd6e948 authored by Gnanarathna E.D.K.V's avatar Gnanarathna E.D.K.V

Merge branch 'master' into 'KIQ-03'

# Conflicts:
#   web-app/frontend/src/components/activities/ActivityContainer.jsx
parents 926dfc5d a5c64cdd
......@@ -45,24 +45,27 @@ def predictAttention():
file = request.files['file']
testNo = request.form.get('questionIndex')
filename = request.form.get('filename')
activity = request.form.get('attentionttype')
candidateID = request.form.get('candidateID')
if file is None or filename == "":
return jsonify({'error: no file'})
return jsonify({'error: no file'})
file.save("./uploads/"+filename)
destination = directory + r"\uploads\att.mp4"
destination = directory + r"\uploads\att.mp4"
scoreLst = captureImage(destination, 10)
dataDict = {
'low_attention': scoreLst[0],
'mid_attention': scoreLst[1],
'high_attention': scoreLst[2],
}
'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": dataDict,
"createdAt":dt_string,
})
"candidateID": candidateID,
"activityName": activity,
"questionIndex": testNo,
"attentionLevelScore": dataDict,
"createdAt": dt_string,
})
print("Prediction02", scoreLst)
print("Prediction", dataDict)
return jsonify(dataJson)
......@@ -108,7 +111,7 @@ def data():
institute = body['institute']
status = body['status']
parent = body['parent']
db.db['users'].insert_one({
"firstName": firstName,
"lastName": lastName,
......@@ -154,15 +157,16 @@ def data():
'age': age,
'residence': residence,
'disorders': disorders,
'email' : email,
'contactNo' : contactNo,
'institute' : institute,
'status' : status,
'parent' : parent
'email': email,
'contactNo': contactNo,
'institute': institute,
'status': status,
'parent': parent
}
dataJson.append(dataDict)
return jsonify(dataJson)
@app.route('/institutes/', methods=['GET'])
@cross_origin()
def data3():
......@@ -371,7 +375,7 @@ def predictShapePattern():
# Reasoning IQ evaluation
@app.route('/predictPictureConcept', methods = ['POST','GET'])
@app.route('/predictPictureConcept', methods=['POST', 'GET'])
@cross_origin()
def predictPictureConcept():
if request.method == 'POST':
......@@ -386,19 +390,20 @@ def predictPictureConcept():
file.save("./"+file.filename)
prediction = transform_audio(file.filename)
activityName = "Picture Concept"
analysis = reasoningIQScoreCalculator(activityName,questionIndex,prediction)
analysis = reasoningIQScoreCalculator(
activityName, questionIndex, prediction)
db.db['reasoningIQScore'].insert_one({
"activityName": activityName,
"candidateID": candidateID,
"questionIndex": questionIndex,
"transcription": prediction,
"score":analysis[0],
"expectedAnswer":analysis[1]
"score": analysis[0],
"expectedAnswer": analysis[1]
})
return jsonify({"msg": "Prediction completed"})
except:
return jsonify({"error": "Error during pipeline execution"})
@app.route('/predictArithmetic', methods=['POST', 'GET'])
@cross_origin()
......@@ -500,6 +505,7 @@ def predictKnowledgeIq():
# Running app
if __name__ == "__main__":
app.secret_key = os.urandom(24)
app.run(host="192.168.43.120",ssl_context='adhoc',debug=True, use_reloader=False)
app.run(host="172.20.10.7", ssl_context='adhoc',
debug=True, use_reloader=False)
flask_cors.CORS(app, expose_headers='Authorization')
{
"name": "web-app-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@headlessui/react": "^1.6.6",
"@heroicons/react": "^1.0.6",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.3",
"@mui/x-date-pickers": "^5.0.0-beta.3",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"date-fns": "^2.29.1",
"file-saver": "^2.0.5",
"formik": "^2.2.9",
"react": "^18.2.0",
"react-circular-progressbar": "^2.0.4",
"react-countdown-circle-timer": "^3.0.9",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"react-image-crop": "^10.0.7",
"react-record-webcam": "^0.0.14",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-signature-canvas": "^1.0.6",
"react-spinners": "^0.13.4",
"recordrtc": "^5.6.2",
"validator": "^13.7.0",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^10.4.8",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.7"
}
"name": "web-app-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@headlessui/react": "^1.6.6",
"@heroicons/react": "^1.0.6",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.3",
"@mui/x-date-pickers": "^5.0.0-beta.3",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"date-fns": "^2.29.1",
"file-saver": "^2.0.5",
"formik": "^2.2.9",
"react": "^18.2.0",
"react-circular-progressbar": "^2.0.4",
"react-countdown-circle-timer": "^3.0.9",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"react-image-crop": "^10.0.7",
"react-record-webcam": "^0.0.14",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-signature-canvas": "^1.0.6",
"react-spinners": "^0.13.4",
"react-webcam": "^7.0.1",
"recordrtc": "^5.6.2",
"validator": "^13.7.0",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^10.4.8",
"postcss": "^8.4.14",
"tailwindcss": "^3.1.7"
}
}
......@@ -32,7 +32,7 @@
border: solid gainsboro;
border-radius: 5px;
padding: 5px;
/* padding: 5px; */
}
.activity-container-navigator-item {
......
import React, { useState, useRef, useEffect } from "react";
import VideoPlayerScreen2 from "../videoPlayer2";
function AnalyticalAttention() {
return (
<p>Hello</p>
)
const [currentLevel, setCurrentLevel] = useState(4);
const [attention, setattention] = useState([]);
useEffect(() => {
console.log("Checking currentLevel:", currentLevel);
}, [currentLevel]);
const changeActivityLevel = (state) => {
setTimeout(async () => {
await console.log("video has ended", state);
await setCurrentLevel(currentLevel + 1);
await console.log("Level is :", currentLevel);
}, 2000);
};
return (
<>
<div className="overflow-hidden bg-white shadow sm:rounded-lg">
<div className="m-1 p-2">
{currentLevel === 4 && (
<VideoPlayerScreen2
currentActivtyIndex={4}
activityType={"AnalyticalAttention"}
changeLevel={changeActivityLevel}
/>
)}
{currentLevel === 5 && (
<VideoPlayerScreen2
currentActivtyIndex={5}
activityType={"AnalyticalAttention"}
changeLevel={changeActivityLevel}
/>
)}
{currentLevel === 6 && (
<VideoPlayerScreen2
currentActivtyIndex={6}
activityType={"AnalyticalAttention"}
changeLevel={changeActivityLevel}
/>
)}
</div>
</div>
</>
);
}
export default AnalyticalAttention
\ No newline at end of file
export default AnalyticalAttention;
import React, { useState, useRef, useEffect } from "react";
import React, { useState, useEffect } from "react";
import "./creativeside.css";
import VideoPlayerScreen2 from "../videoPlayer2";
function CreativeAttention () {
return (
<p>Hello creative people</p>
)
function CreativeAttention() {
const [currentLevel, setCurrentLevel] = useState(1);
const [attention, setattention] = useState([]);
useEffect(() => {
console.log("Checking currentLevel:", currentLevel);
}, [currentLevel]);
const changeActivityLevel = (state) => {
setTimeout(async () => {
await console.log("video has ended", state);
await setCurrentLevel(currentLevel + 1);
await console.log("Level is :", currentLevel);
}, 2000);
};
return (
<>
<div className="overflow-hidden bg-white shadow sm:rounded-lg">
<div className="m-1 p-2">
{currentLevel === 1 && (
<VideoPlayerScreen2
currentActivtyIndex={1}
activityType={"CreativeAttention"}
changeLevel={changeActivityLevel}
/>
)}
{currentLevel === 2 && (
<VideoPlayerScreen2
currentActivtyIndex={2}
activityType={"CreativeAttention"}
changeLevel={changeActivityLevel}
/>
)}
{currentLevel === 3 && (
<VideoPlayerScreen2
currentActivtyIndex={3}
activityType={"CreativeAttention"}
changeLevel={changeActivityLevel}
/>
)}
</div>
</div>
</>
);
}
export default CreativeAttention
\ No newline at end of file
export default CreativeAttention;
import React, {useState,useEffect} from "react";
import API from '../../../config/api';
export const predictAttention = async (data) => {
let response;
await API.post("attentionPrediction", data, {
headers: {
"Access-Control-Allow-Origin": "*",
},
})
.then((res) => {
console.log(res.data[0])
response = res.data[0];
})
.catch((err) => {
console.log(err);
});
return response
}
\ No newline at end of file
import React, { useState, useEffect, useRef } from "react";
import Webcam from "react-webcam";
import { predictAttention } from "./predictAttention";
const VideoPlayerScreen2 = ({ currentActivtyIndex, activityType, changeLevel }) => {
const webcamRef = React.useRef(null);
const mediaRecorderRef = React.useRef(null);
const [videoLink, setVideoLink] = useState("");
const vidRef = useRef();
const [capturing, setCapturing] = React.useState(false);
const [recordedChunks, setRecordedChunks] = React.useState([]);
const videoConstraints = {
facingMode: "user",
};
const handleStartCaptureClick = React.useCallback(() => {
console.log("Started recording");
setCapturing(true);
mediaRecorderRef.current = new MediaRecorder(webcamRef.current.stream, {
mimeType: "video/webm",
});
mediaRecorderRef.current.addEventListener(
"dataavailable",
handleDataAvailable
);
mediaRecorderRef.current.start();
}, [webcamRef, setCapturing, mediaRecorderRef]);
const handleDataAvailable = React.useCallback(
({ data }) => {
if (data.size > 0) {
setRecordedChunks((prev) => prev.concat(data));
}
},
[setRecordedChunks]
);
const handleStopCaptureClick = React.useCallback(() => {
mediaRecorderRef.current.stop();
setCapturing(false);
console.log("Stopped recording");
}, [mediaRecorderRef, webcamRef, setCapturing]);
const handlePredict = React.useCallback(() => {
let candidateID = null;
if (localStorage) {
candidateID = localStorage.getItem("candidateID");
}
console.log("Next level")
changeLevel(true);
if (recordedChunks.length) {
console.log("Prediction started");
const blob = new Blob(recordedChunks, {
type: "video/webm",
});
const data = new FormData();
data.append("file", blob);
data.append("filename", "att.mp4");
data.append("questionIndex", currentActivtyIndex);
data.append("attentionttype", activityType);
data.append("candidateID", candidateID);
predictAttention(data);
setRecordedChunks([]);
}
}, [recordedChunks]);
useEffect(() => {
switch (currentActivtyIndex) {
case 1:
setVideoLink("/Videos/drawafish.mp4");
break;
case 2:
setVideoLink("/Videos/singaSong.mp4");
break;
case 3:
setVideoLink("/Videos/makeflowers.mp4");
break;
case 4:
setVideoLink("/Videos/drawafish.mp4");
break;
case 5:
setVideoLink("/Videos/drawafish.mp4");
break;
case 6:
setVideoLink("/Videos/drawafish.mp4");
break;
default:
}
const timer = setTimeout(() => {
vidRef.current.play();
}, 3000);
return () => clearTimeout(timer);
}, [currentActivtyIndex]);
const myCallback = async () => {
await handleStopCaptureClick();
};
const myCallback2 = () => {
handleStartCaptureClick();
};
return (
<>
<div className="w-full m-4 p-4">
<div className="flex items-center">
{videoLink && (
<>
<video
ref={vidRef}
className="w-full h-full p-2"
controls
onEnded={() => myCallback()}
onPlay={() => myCallback2()}
>
<source src={videoLink} type="video/mp4" />
</video>
</>
)}
</div>
{recordedChunks.length > 0 && (
<button onClick={handlePredict}>Next</button>
)}
<div className="invisible h-0 w-0">
<Webcam
audio={false}
videoConstraints={videoConstraints}
ref={webcamRef}
/>
</div>
</div>
</>
);
};
export default VideoPlayerScreen2;
import axios from "axios";
export default axios.create({
baseURL: `http://127.0.0.1:5000/`,
baseURL: `https://172.20.10.7:5000/`,
});
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