Writing and speaking rework, some changes to module upload

This commit is contained in:
Carlos-Mesquita
2024-11-25 16:41:38 +00:00
parent a54dfad43a
commit a7da187ec6
20 changed files with 495 additions and 195 deletions

View File

@@ -12,7 +12,6 @@ from typing import List
from http import HTTPStatus
import httpx
import whisper
from fastapi import FastAPI, Request
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
@@ -27,6 +26,7 @@ from app.api import router
from app.configs import DependencyInjector
from app.exceptions import CustomException
from app.middlewares import AuthenticationMiddleware, AuthBackend
from app.services.impl import OpenAIWhisper
@asynccontextmanager
@@ -36,8 +36,6 @@ async def lifespan(_app: FastAPI):
https://fastapi.tiangolo.com/advanced/events/
"""
# Whisper model
whisper_model = whisper.load_model("base")
# NLTK required datasets download
nltk.download('words')
@@ -56,11 +54,12 @@ async def lifespan(_app: FastAPI):
)
http_client = httpx.AsyncClient()
stt = OpenAIWhisper()
DependencyInjector(
polly_client,
http_client,
whisper_model
stt
).inject()
# Setup logging
@@ -72,6 +71,7 @@ async def lifespan(_app: FastAPI):
yield
stt.close()
await http_client.aclose()
await polly_client.close()
await context_stack.aclose()