Spaces:
Sleeping
Sleeping
File size: 2,734 Bytes
c71e312 b6d5cb2 c71e312 b6d5cb2 c71e312 b6d5cb2 c71e312 b6d5cb2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
from datetime import datetime
from uuid import uuid4
from typing import Any
from src.expon.feedback.domain.model.feedback import Feedback
from src.expon.feedback.infrastructure.services.text_generation_service import TextGenerationService
from src.expon.presentation.infrastructure.persistence.jpa.repositories.presentation_repository import PresentationRepository
from src.expon.feedback.infrastructure.persistence.jpa.feedback_repository import FeedbackRepository
from src.expon.presentation.infrastructure.persistence.jpa.models.presentation_orm import PresentationORM
class GenerateFeedbackService:
def __init__(self, feedback_repo: FeedbackRepository, presentation_repo: PresentationRepository):
self.feedback_repo = feedback_repo
self.presentation_repo = presentation_repo
self.text_gen_service = TextGenerationService()
def generate_feedback(self, presentation_id: str) -> dict[str, Any]:
# 1. Buscar presentación
presentation: PresentationORM = self.presentation_repo.get_by_id(presentation_id)
if presentation is None:
raise ValueError("Presentación no encontrada")
user_id = presentation.user_id
emotion = presentation.dominant_emotion
transcription = presentation.transcript or ""
confidence = presentation.confidence or 0.0
anxiety = 0.3 # Puedes cambiarlo si luego deseas calcularlo
# 2. Generar contenido dinámico con IA
general, language, confidence_fb, anxiety_fb, suggestions = self.text_gen_service.generate_structured_feedback(
transcription=transcription,
emotion=emotion,
confidence=confidence,
anxiety=anxiety
)
feedback = Feedback(
id=uuid4(),
user_id=user_id,
presentation_id=presentation_id,
general_feedback=general,
language_feedback=language,
confidence_feedback=confidence_fb,
anxiety_feedback=anxiety_fb,
suggestions=suggestions,
created_at=datetime.utcnow()
)
self.feedback_repo.save(feedback)
return {
"id": feedback.id,
"user_id": feedback.user_id,
"presentation_id": feedback.presentation_id,
"general_feedback": feedback.general_feedback,
"language_feedback": feedback.language_feedback,
"confidence_feedback": feedback.confidence_feedback,
"anxiety_feedback": feedback.anxiety_feedback,
"suggestions": feedback.suggestions,
"created_at": feedback.created_at,
"dominant_emotion": emotion,
"confidence": round(confidence, 2)
}
|