Spaces:
Runtime error
Runtime error
| # # api.py | |
| # from fastapi import FastAPI, HTTPException | |
| # from pydantic import BaseModel | |
| # from typing import List | |
| # from fastapi.responses import JSONResponse | |
| # from fastapi.middleware.cors import CORSMiddleware | |
| # app = FastAPI() | |
| # app.add_middleware( | |
| # CORSMiddleware, | |
| # allow_origins=["*"], | |
| # allow_credentials=True, | |
| # allow_methods=["*"], | |
| # allow_headers=["*"], | |
| # ) | |
| # class TranslationRequest(BaseModel): | |
| # sentences: List[str] | |
| # target_lang: str | |
| # @app.get("/health") | |
| # async def health_check(): | |
| # return {"status": "healthy"} | |
| # @app.post("/translate") | |
| # async def translate(request: TranslationRequest): | |
| # try: | |
| # from app import translate_text | |
| # result = translate_text( | |
| # sentences=request.sentences, | |
| # target_lang=request.target_lang | |
| # ) | |
| # return JSONResponse(content=result) | |
| # except Exception as e: | |
| # raise HTTPException(status_code=500, detail=str(e)) |