19 lines
492 B
Python
19 lines
492 B
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
from services.translate import translate_to_russian
|
|
|
|
router = APIRouter(prefix="/translate", tags=["translate"])
|
|
|
|
|
|
class TranslateRequest(BaseModel):
|
|
text: str
|
|
|
|
|
|
@router.post("/")
|
|
async def translate(req: TranslateRequest):
|
|
try:
|
|
result = await translate_to_russian(req.text)
|
|
return {"translated": result}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=502, detail=str(e))
|