Patched backend eval

This commit is contained in:
Carlos-Mesquita
2024-11-26 09:08:12 +00:00
parent 6e0276b79d
commit 47cdfe1478
9 changed files with 47 additions and 21 deletions

View File

@@ -10,6 +10,7 @@ class IEvaluationService(ABC):
@abstractmethod
async def create_evaluation(
self,
user_id: str,
session_id: str,
exercise_id: str,
eval_type: EvaluationType,
@@ -20,7 +21,7 @@ class IEvaluationService(ABC):
@abstractmethod
async def begin_evaluation(
self,
session_id: str, task: int,
user_id: str, session_id: str, task: int,
exercise_id: str, exercise_type: str,
solution: any,
background_tasks: BackgroundTasks

View File

@@ -20,6 +20,7 @@ class EvaluationService(IEvaluationService):
async def create_evaluation(
self,
user_id: str,
session_id: str,
exercise_id: str,
eval_type: EvaluationType,
@@ -28,6 +29,7 @@ class EvaluationService(IEvaluationService):
await self._db.save_to_db(
"evaluation",
{
"user": user_id,
"session_id": session_id,
"exercise_id": exercise_id,
"type": eval_type,
@@ -38,20 +40,20 @@ class EvaluationService(IEvaluationService):
async def begin_evaluation(
self,
session_id: str, task: int,
user_id: str, session_id: str, task: int,
exercise_id: str, exercise_type: str,
solution: Union[WritingGradeTaskDTO, List[GradeSpeakingItem]],
background_tasks: BackgroundTasks
):
background_tasks.add_task(
self._begin_evaluation,
session_id, task,
user_id, session_id, task,
exercise_id, exercise_type,
solution
)
async def _begin_evaluation(
self, session_id: str, task: int,
self, user_id: str, session_id: str, task: int,
exercise_id: str, exercise_type: str,
solution: Union[WritingGradeTaskDTO, List[GradeSpeakingItem]]
):
@@ -71,6 +73,7 @@ class EvaluationService(IEvaluationService):
await self._db.update(
"evaluation",
{
"user": user_id,
"exercise_id": exercise_id,
"session_id": session_id,
},
@@ -87,6 +90,7 @@ class EvaluationService(IEvaluationService):
await self._db.update(
"evaluation",
{
"user": user_id,
"exercise_id": exercise_id,
"session_id": session_id
},

View File

@@ -1,6 +1,8 @@
import asyncio
import logging
import os
from uuid import uuid4
import aiofiles
import re
import uuid
@@ -249,7 +251,17 @@ class SpeakingService(ISpeakingService):
response['perfect_answer'] = perfect_answers[0]["answer"]
solutions = []
for file_name in temp_files:
solutions.append(await self._file_storage.upload_file_firebase_get_url(f'{FilePaths.FIREBASE_SPEAKING_VIDEO_FILES_PATH}{uuid4()}.wav', file_name))
response["overall"] = self._fix_speaking_overall(response["overall"], response["task_response"])
response["solutions"] = solutions
if task in {1,3}:
response["answer"] = solutions
else:
response["fullPath"] = solutions[0]
self._log(task, request_id, f'Final response: {response}')
return response
@@ -266,7 +278,7 @@ class SpeakingService(ISpeakingService):
@staticmethod
async def save_file(item: GradeSpeakingItem) -> str:
sound_file_name = FilePaths.AUDIO_FILES_PATH + str(uuid.uuid4())
sound_file_name = "tmp/" + str(uuid.uuid4())
content = await item.answer.read()
async with aiofiles.open(sound_file_name, 'wb') as f:
await f.write(content)

View File

@@ -26,7 +26,7 @@ class OpenAIWhisper(ISpeechToTextService):
self._is_closed = False
for i in range(num_models):
self._models[i] = whisper.load_model(self._model_name)
self._models[i] = whisper.load_model(self._model_name, in_memory=True)
self._executor = ThreadPoolExecutor(
max_workers=num_models,