У меня есть рабочий код. Я хочу, чтобы был добавлен код из этого репозитория, как…
Private research annotation
Sign in to add a private research label or note.
- User
У меня есть рабочий код. Я хочу, чтобы был добавлен код из этого репозитория, как отдельный адаптер. Как это сделать? Код: import os import tempfile from typing import Annotated, List, Any
import whisper from litestar import Controller, post, get, Response from litestar.enums import RequestEncodingType, MediaType from litestar.exceptions import HTTPException from litestar.params import Body
from src.schemas.request import FormRequest, TranscriptionRequest from src.schemas.response import TranscriptionResult from src.services.model_manager import model_manager from src.services.transcription import transcription_service
class TranscriptionController(Controller): path = "/api/v1/transcription"
code@post("/", media_type=MediaType.JSON) async def router_transcribe( self, data: Annotated[FormRequest, Body(media_type=RequestEncodingType.MULTI_PART)], ) -> Response[Any]: """ Transcribe audio file with specified parameters and return results in requested formats """ temp_file = None try: file_content = await data.file.read() request = TranscriptionRequest(**data.model_dump()) # Создаем временный файл temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav') temp_file.write(file_content) temp_file.close() result = await transcription_service.transcribe_and_format( temp_file.name, request ) return Response(content=TranscriptionResult(**result), status_code=200) except Exception as e: raise HTTPException( status_code=500, detail=str(e) ) finally: # Удаляем временный файл if temp_file and os.path.exists(temp_file.name): os.unlink(temp_file.name) @get("/models") async def list_models(self) -> List[str]: """List available whisper models""" return list(whisper.available_models()) @post("/download/{model_name:str}") async def download_model(self, model_name: str) -> dict: """ Download a specific model """ try: model = model_manager.get_model(model_name) return {"status": "success", "message": f"Model {model_name} downloaded successfully"} except Exception as e: raise HTTPException( status_code=500, detail=f"Failed to download model: {str(e)}" ) Assistant
Чтобы добавить код из репозитория stable-ts как отдельный адаптер, вы можете создать новый модуль, например,
stable_ts_adapter.py, и импортировать его в ваш контроллер.В модуле
stable_ts_adapter.pyвы можете импортировать необходимые классы и функции из репозитория stable-ts и создать свой класс-адаптер, который будет использовать эти функции для транскрипции аудиофайлов.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.