Commit 177d394a authored by H.M.C. Nadunithara Wijerathne's avatar H.M.C. Nadunithara Wijerathne

Merge branch 'it19953298' into 'master'

Voice analysis timeout

See merge request !6
parents 391d4c85 346ad209
...@@ -75,11 +75,13 @@ router.put( ...@@ -75,11 +75,13 @@ router.put(
let update = req.body.update; let update = req.body.update;
if (update.interview?.videoRef) { if (update.interview?.videoRef) {
VoiceAPI.verifyVoice({ try {
video_url: update.interview?.videoRef, VoiceAPI.verifyVoice({
user_id: req.body.candidateId, video_url: update.interview?.videoRef,
application_id: req.body.applicationId, user_id: req.body.candidateId,
}); application_id: req.body.applicationId,
});
} catch (error) {}
} }
Application.findByIdAndUpdate(req.body.applicationId, { Application.findByIdAndUpdate(req.body.applicationId, {
...@@ -95,6 +97,30 @@ router.put( ...@@ -95,6 +97,30 @@ router.put(
} }
); );
router.put(
"/update/voice-verification",
async (
req: TypedRequest<
{},
{
applicationId: string;
update: number;
}
>,
res
) => {
const update = req.body.update.toString();
Application.findByIdAndUpdate(req.body.applicationId, {
$set: { "interview.voiceVerification": update },
})
.then((_application) => {
res.send("success");
})
.catch((err) => res.send(err));
}
);
router.post( router.post(
"/analyse", "/analyse",
authMiddleware, authMiddleware,
......
...@@ -13,6 +13,7 @@ router.post( ...@@ -13,6 +13,7 @@ router.post(
async (req: TypedRequest<{ userId: string }, CandidateType>, res) => { async (req: TypedRequest<{ userId: string }, CandidateType>, res) => {
try { try {
const update = req.body; const update = req.body;
if (req.body?.resume) { if (req.body?.resume) {
const data: any = await ResumeAPI.extractResumeData({ const data: any = await ResumeAPI.extractResumeData({
user_id: req.query.userId, user_id: req.query.userId,
...@@ -20,13 +21,16 @@ router.post( ...@@ -20,13 +21,16 @@ router.post(
}); });
update.resumeData = data; update.resumeData = data;
} }
await Candidates.findByIdAndUpdate(req.query.userId, { $set: update });
if (req.body?.selfIntro) { if (req.body?.selfIntro) {
VoiceAPI.enrollVoice({ try {
user_id: req.query.userId, VoiceAPI.enrollVoice({
video_url: req.body.selfIntro, user_id: req.query.userId,
}); video_url: req.body.selfIntro,
});
} catch (error) {}
} }
await Candidates.findByIdAndUpdate(req.query.userId, { $set: req.body });
return res.status(200).json({ data: req.body }); return res.status(200).json({ data: req.body });
} catch (error) { } catch (error) {
return res.status(400).send(error); return res.status(400).send(error);
......
...@@ -31,7 +31,7 @@ export const request = ( ...@@ -31,7 +31,7 @@ export const request = (
data, data,
params, params,
headers, headers,
timeout: 30000, timeout: 90000,
}) })
.then(async (response: AxiosResponse) => { .then(async (response: AxiosResponse) => {
resolve(response.data); resolve(response.data);
......
...@@ -10,6 +10,7 @@ from scripts.processing import extract_input_feature ...@@ -10,6 +10,7 @@ from scripts.processing import extract_input_feature
from keras.models import load_model from keras.models import load_model
from scripts.parameters import MODEL_FILE, MAX_SEC from scripts.parameters import MODEL_FILE, MAX_SEC
from scripts.voice_feature_extraction import get_embedding from scripts.voice_feature_extraction import get_embedding
from scripts.api import SingletonAiohttp
router = APIRouter(prefix='/voice') router = APIRouter(prefix='/voice')
...@@ -33,17 +34,17 @@ def enroll(payload:EnrollVoice): ...@@ -33,17 +34,17 @@ def enroll(payload:EnrollVoice):
try: try:
os.remove(video_filename) os.remove(video_filename)
except: except:
print('error') print('')
try: try:
os.remove(audio_filename) os.remove(audio_filename)
except: except:
print('error') print('')
return 'SUCCESS' return 'SUCCESS'
@router.post("/verify") @router.post("/verify")
def verify(payload:VerifyVoice): async def verify(payload:VerifyVoice):
video_filename = 'videos/interviews/'+payload.application_id+'.mp4' video_filename = 'videos/interviews/'+payload.application_id+'.mp4'
urllib.request.urlretrieve(payload.video_url, video_filename) urllib.request.urlretrieve(payload.video_url, video_filename)
...@@ -58,8 +59,12 @@ def verify(payload:VerifyVoice): ...@@ -58,8 +59,12 @@ def verify(payload:VerifyVoice):
test_embs = np.array(test_result.tolist()) test_embs = np.array(test_result.tolist())
enroll_embs = np.load("voices/auth/embed/"+ payload.user_id+".npy") enroll_embs = np.load("voices/auth/embed/"+ payload.user_id+".npy")
distance = euclidean(test_embs, enroll_embs) distance = euclidean(test_embs, enroll_embs)
url = "http://localhost:5000/applications/update/voice-verification"
payload = {'update':round(1-distance, 5), 'applicationId':payload.application_id }
return round(1-distance, 5) await SingletonAiohttp.put_url(url, payload)
return 'success'
@router.post("/analyse") @router.post("/analyse")
def analys(payload:AnalyseVoice): def analys(payload:AnalyseVoice):
......
import aiohttp
from socket import AF_INET
from typing import List, Optional, Any, Dict
SIZE_POOL_AIOHTTP = 100
class SingletonAiohttp:
aiohttp_client: Optional[aiohttp.ClientSession] = None
@classmethod
def get_aiohttp_client(cls) -> aiohttp.ClientSession:
if cls.aiohttp_client is None:
timeout = aiohttp.ClientTimeout(total=2)
connector = aiohttp.TCPConnector(family=AF_INET, limit_per_host=SIZE_POOL_AIOHTTP)
cls.aiohttp_client = aiohttp.ClientSession(timeout=timeout, connector=connector)
return cls.aiohttp_client
@classmethod
async def close_aiohttp_client(cls) -> None:
if cls.aiohttp_client:
await cls.aiohttp_client.close()
cls.aiohttp_client = None
@classmethod
async def post_url(cls, url: str) -> Any:
client = cls.get_aiohttp_client()
try:
async with client.post(url) as response:
if response.status != 200:
return {"ERROR OCCURED" + str(await response.text())}
json_result = await response.json()
except Exception as e:
return {"ERROR": e}
return json_result
@classmethod
async def put_url(cls, url: str, payload) -> Any:
client = cls.get_aiohttp_client()
try:
async with client.put(url, data=payload) as response:
if response.status != 200:
return {"ERROR OCCURED" + str(await response.text())}
json_result = await response.json()
except Exception as e:
return {"ERROR": e}
return json_result
\ No newline at end of file
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