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(
let update = req.body.update;
if (update.interview?.videoRef) {
VoiceAPI.verifyVoice({
video_url: update.interview?.videoRef,
user_id: req.body.candidateId,
application_id: req.body.applicationId,
});
try {
VoiceAPI.verifyVoice({
video_url: update.interview?.videoRef,
user_id: req.body.candidateId,
application_id: req.body.applicationId,
});
} catch (error) {}
}
Application.findByIdAndUpdate(req.body.applicationId, {
......@@ -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(
"/analyse",
authMiddleware,
......
......@@ -13,6 +13,7 @@ router.post(
async (req: TypedRequest<{ userId: string }, CandidateType>, res) => {
try {
const update = req.body;
if (req.body?.resume) {
const data: any = await ResumeAPI.extractResumeData({
user_id: req.query.userId,
......@@ -20,13 +21,16 @@ router.post(
});
update.resumeData = data;
}
await Candidates.findByIdAndUpdate(req.query.userId, { $set: update });
if (req.body?.selfIntro) {
VoiceAPI.enrollVoice({
user_id: req.query.userId,
video_url: req.body.selfIntro,
});
try {
VoiceAPI.enrollVoice({
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 });
} catch (error) {
return res.status(400).send(error);
......
......@@ -31,7 +31,7 @@ export const request = (
data,
params,
headers,
timeout: 30000,
timeout: 90000,
})
.then(async (response: AxiosResponse) => {
resolve(response.data);
......
......@@ -10,6 +10,7 @@ from scripts.processing import extract_input_feature
from keras.models import load_model
from scripts.parameters import MODEL_FILE, MAX_SEC
from scripts.voice_feature_extraction import get_embedding
from scripts.api import SingletonAiohttp
router = APIRouter(prefix='/voice')
......@@ -33,17 +34,17 @@ def enroll(payload:EnrollVoice):
try:
os.remove(video_filename)
except:
print('error')
print('')
try:
os.remove(audio_filename)
except:
print('error')
print('')
return 'SUCCESS'
@router.post("/verify")
def verify(payload:VerifyVoice):
async def verify(payload:VerifyVoice):
video_filename = 'videos/interviews/'+payload.application_id+'.mp4'
urllib.request.urlretrieve(payload.video_url, video_filename)
......@@ -58,8 +59,12 @@ def verify(payload:VerifyVoice):
test_embs = np.array(test_result.tolist())
enroll_embs = np.load("voices/auth/embed/"+ payload.user_id+".npy")
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")
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