Commit c0ed14a6 authored by AdithyaKahawanugoda's avatar AdithyaKahawanugoda

backend ssl adhoc configured

parent 72bfbe6a
import difflib
import re
from fuzzywuzzy import fuzz, process
# picture concept possible answer list
pc1 = "ගස් ගහ ගහක්"
pc2 = "කුරුල්ලා කුරුල්ලෝ කුරුල්ලෙක්"
pc3 = "වාහන"
pc4 = "පලතුරු"
pc5 = "එළවළු කෑම කන දේවල්"
pc6 = "සත්තු"
pcAnswers = ["ගස් ගහ ගහක්","කුරුල්ලා කුරුල්ලෝ කුරුල්ලෙක්","වාහන","පලතුරු","එළවළු කෑම කන දේවල්","සත්තු"]
# arithmetic possible answer list
ar1 = "තුන තුනක් 3"
ar2 = "හය හයක් 6"
ar3 = "දහය දහයක් 10"
arAnswers = ["තුන තුනක් 3","හය හයක් 6","දහය දහයක් 10"]
# test values
s1 = "ගස්"
s2 = "මේ තියෙන්නේ ගහ යට පෙළී තියෙන්නෙත් ගහක් එ හින්ද උත්තරේ ගස්"
s3 = "ගස් ගහ ගහක්" # possible answers (words)
s4 = ["මේ තියෙන්නේ ගහක්", "යට පෙළී තියෙන්නෙත් ගහක් එ හින්ද උත්තරේ ගස්", "උත්තරේ ගස්"] # transcription array
# def testFunc():
# print(fuzz.ratio(s1,s2),"-ratio")
# print(fuzz.partial_ratio(s1,s2),"-partial_ratio s1-s2")
# print(fuzz.token_sort_ratio(s1,s2),"-token_sort_ratio")
# print(fuzz.token_set_ratio(s1,s2),"-token_set_ratio")
# print(fuzz.partial_token_sort_ratio(s3,s4),"-partial_token_sort_ratio")
# print(fuzz.partial_token_set_ratio(s3,s4),"-partial_token_set_ratio")
# print(process.extract(s3,s4,limit=2,scorer=fuzz.token_sort_ratio), "process-extract-token_sort")
# print(process.extract(s3,s4,limit=2,scorer=fuzz.token_set_ratio), "process-extract-token_set")
# print(process.extract(s3,s4,limit=2,scorer=fuzz.partial_token_sort_ratio), "process-extract-partial_token_sort")
# print(process.extract(s3,s4,limit=2,scorer=fuzz.partial_token_set_ratio), "process-extract-partial_token_set")
def reasoningIQScoreCalculator(activity, questionIndex, prediction):
questionIndex = int(questionIndex)
predictionStr = " ".join(prediction)
expectedAnswer = ""
score = []
analysis = []
if (activity == "Picture Concept"):
answerIndex = questionIndex-1
expectedAnswer = pcAnswers[answerIndex]
score = process.extract(expectedAnswer,prediction,limit=4,scorer=fuzz.partial_token_set_ratio)
elif (activity == "Arithmetic"):
answerIndex = questionIndex-1
expectedAnswer = arAnswers[answerIndex]
score = process.extract(expectedAnswer,prediction,limit=4,scorer=fuzz.partial_token_set_ratio)
else:
score = []
print('Invalid Activity Name')
analysis = [score, expectedAnswer]
return analysis
# print(reasoningIQScoreCalculator("Picture Concept","1",s4))
\ No newline at end of file
......@@ -12,6 +12,7 @@ import base64
import io
from preProcessor import transform_audio
from knowledgeIqScoreCalculation import calKnowledgeIqActivityScore
from reasoningIqScoreCalculation import reasoningIQScoreCalculator
# Libraries required for model utilization
import cv2 as cv
import numpy as np
......@@ -368,10 +369,9 @@ def predictShapePattern():
return jsonify(response)
# Reasoning IQ evaluation
@app.route('/predictPictureConcept', methods=['POST', 'GET'])
# Reasoning IQ evaluation
@app.route('/predictPictureConcept', methods = ['POST','GET'])
@cross_origin()
def predictPictureConcept():
if request.method == 'POST':
......@@ -380,24 +380,25 @@ def predictPictureConcept():
candidateID = request.form.get('candidateID')
print(questionIndex)
if file is None or file.filename == "":
return jsonify({'error: no file'})
return jsonify({"error": "no file"})
try:
file.save("./"+file.filename)
prediction = transform_audio(file.filename)
data = {'prediction': prediction}
activityName = "Picture Concept"
analysis = reasoningIQScoreCalculator(activityName,questionIndex,prediction)
db.db['reasoningIQScore'].insert_one({
"activityName": "Picture Concept",
"activityName": activityName,
"candidateID": candidateID,
"questionIndex": questionIndex,
"transcription": prediction,
"score":analysis[0],
"expectedAnswer":analysis[1]
})
return jsonify(data)
return jsonify({"msg": "Prediction completed"})
except:
return jsonify({'error: Error during pipeline execution'})
return jsonify({'result: test'})
return jsonify({"error": "Error during pipeline execution"})
@app.route('/predictArithmetic', methods=['POST', 'GET'])
@cross_origin()
......@@ -497,6 +498,6 @@ def predictKnowledgeIq():
# Running app
if __name__ == "__main__":
app.secret_key = os.urandom(24)
app.run(debug=True, use_reloader=False)
app.run(host="192.168.8.169",ssl_context='adhoc',debug=True, use_reloader=False)
flask_cors.CORS(app, expose_headers='Authorization')
import React, { useState, useEffect, useRef } from "react";
import { render } from 'react-dom';
import { render } from "react-dom";
import "./ethicalClearence.css";
import toast, { Toaster } from "react-hot-toast";
import { ContainerCard } from "../../components/index";
......@@ -25,7 +25,7 @@ const EthicalClearenceScreen = () => {
const sigRef = useRef();
const navigate = useNavigate();
const [parentName, setParentName] = useState("");
const [childCandidate, setchildCandidate] = useState("");
const [childCandidate, setChildCandidate] = useState("");
const [childName, setchildName] = useState("");
const [childData, setChildData] = useState([{}]);
const [isFormFilled, setIsFormFilled] = useState(false);
......@@ -34,12 +34,12 @@ const EthicalClearenceScreen = () => {
const handleSignatureEnd = () => {
setSignature(sigRef.current.toDataURL());
}
};
const clearSignature = () => {
sigRef.current.clear();
setSignature(null);
}
};
// useEffect(() => {
// console.log(signature);
......@@ -94,16 +94,16 @@ const EthicalClearenceScreen = () => {
.then((res) => {
if (res.status === 200) {
if (localStorage) {
localStorage.setItem("candidateID", childName);
localStorage.setItem("candidateID", childCandidate);
}
setParentName("");
setchildCandidate("");
setChildCandidate("");
setSignature(null);
toast.success("Details have been submitted");
setIsFormFilled(true);
} else {
setParentName("");
setchildCandidate("");
setChildCandidate("");
setSignature(null);
toast.error("Some error occured");
}
......@@ -120,8 +120,9 @@ const EthicalClearenceScreen = () => {
const getChildName = (parent) => {
const selectedChild = childData.find((item) => item.parent === parent);
setchildName(selectedChild.firstName);
setChildCandidate(selectedChild.id);
console.log(childName);
}
};
const onStart = () => {
recordWebcam.close();
navigate("/activities");
......@@ -175,11 +176,10 @@ const EthicalClearenceScreen = () => {
name="childCandidate"
defaultValue={"DEFAULT"}
className="mt-1 block text-black w-40 py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
onChange={(e) =>{
onChange={(e) => {
getChildName(e.target.value);
setParentName(e.target.value);
}
}
}}
>
<option value="DEFAULT" disabled>
Select ...
......@@ -233,12 +233,12 @@ const EthicalClearenceScreen = () => {
canvasProps={{
width: 500,
height: 200,
className: "sigCanvas"
className: "sigCanvas",
}}
ref={sigRef}
onEnd={handleSignatureEnd}
/>
{/* <button
{/* <button
className="inline-flex justify-center mr-2 py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-[#3d59c1] hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
onClick={clearSignature}
>
......@@ -250,7 +250,10 @@ const EthicalClearenceScreen = () => {
<div className="px-4 py-3 bg-gray-50 text-right sm:px-6">
<button
className="inline-flex justify-center mr-2 py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-[#3d59c1] hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
onClick={() => {recordWebcam.close(); navigate("/");} }
onClick={() => {
recordWebcam.close();
navigate("/");
}}
>
Back
</button>
......@@ -295,9 +298,12 @@ const EthicalClearenceScreen = () => {
/>
<button
type="button"
onClick={() => {recordWebcam.close(); navigate("/");} }
onClick={() => {
recordWebcam.close();
navigate("/");
}}
>
Back to Home
Back to Home
</button>
<button
type="button"
......
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