Initial commit: mBART Translation API with Docker support
- FastAPI 기반 다국어 번역 REST API 서비스 - mBART-50 모델을 사용한 18개 언어 지원 - Docker 및 Docker Compose 설정 포함 - GPU/CPU 지원 - 헬스 체크 및 API 문서 자동 생성 - 외부 접속 지원 (172.30.1.2:8000) 주요 파일: - main.py: FastAPI 애플리케이션 - translator.py: mBART 번역 서비스 - models.py: Pydantic 데이터 모델 - config.py: 환경 설정 - Dockerfile: 최적화된 Docker 이미지 - docker-compose.yml: 간편한 배포 설정 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
52
models.py
Normal file
52
models.py
Normal file
@ -0,0 +1,52 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class TranslationRequest(BaseModel):
|
||||
"""번역 요청 모델"""
|
||||
|
||||
text: str = Field(..., description="번역할 텍스트", min_length=1)
|
||||
source_lang: str = Field(..., description="소스 언어 코드 (예: ko, en, ja)")
|
||||
target_lang: str = Field(..., description="타겟 언어 코드 (예: en, ko, ja)")
|
||||
|
||||
class Config:
|
||||
json_schema_extra = {
|
||||
"example": {
|
||||
"text": "안녕하세요, 반갑습니다.",
|
||||
"source_lang": "ko",
|
||||
"target_lang": "en",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TranslationResponse(BaseModel):
|
||||
"""번역 응답 모델"""
|
||||
|
||||
translated_text: str = Field(..., description="번역된 텍스트")
|
||||
source_lang: str = Field(..., description="소스 언어 코드")
|
||||
target_lang: str = Field(..., description="타겟 언어 코드")
|
||||
original_text: str = Field(..., description="원본 텍스트")
|
||||
|
||||
class Config:
|
||||
json_schema_extra = {
|
||||
"example": {
|
||||
"translated_text": "Hello, nice to meet you.",
|
||||
"source_lang": "ko",
|
||||
"target_lang": "en",
|
||||
"original_text": "안녕하세요, 반갑습니다.",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
"""헬스 체크 응답 모델"""
|
||||
|
||||
status: str = Field(..., description="서비스 상태")
|
||||
model_loaded: bool = Field(..., description="모델 로드 여부")
|
||||
device: str = Field(..., description="사용 중인 디바이스 (cpu/cuda)")
|
||||
|
||||
|
||||
class LanguagesResponse(BaseModel):
|
||||
"""지원 언어 목록 응답 모델"""
|
||||
|
||||
supported_languages: dict = Field(..., description="지원하는 언어 코드 목록")
|
||||
Reference in New Issue
Block a user