File size: 630 Bytes
8bcd16e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# api.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List
from app import translate_text

app = FastAPI()

class InputData(BaseModel):
    sentences: List[str]
    target_lang: str

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

@app.post("/translate")
async def translate(input_data: InputData):
    try:
        result = translate_text(
            sentences=input_data.sentences,
            target_lang=input_data.target_lang
        )
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))