From 79f674d8f225610e2dc94aec8b212b3ccd925f84 Mon Sep 17 00:00:00 2001 From: PleahMaCaka Date: Thu, 2 Nov 2023 11:50:59 +0900 Subject: [PATCH] feat: replace deepl endpoint to `/toKr` --- main.py | 4 ++-- routers/deepl.py | 19 ------------------- routers/translate.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 routers/deepl.py create mode 100644 routers/translate.py diff --git a/main.py b/main.py index f1c83b8..fb940bf 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ from starlette.middleware.cors import CORSMiddleware from core.sql_util import check_and_create_table -from routers import deepl, location, subway, weather, auth +from routers import translate, location, subway, weather, auth # from service.summary.nlp_util import update_nlp_client @@ -24,7 +24,7 @@ app.include_router(weather.router, prefix="/service/weather", tags=["weather"]) # app.include_router(summary.router, prefix="/service/summary", tags=["summary"]) app.include_router(subway.router, prefix="/service/subway", tags=["subway"]) -app.include_router(deepl.router, prefix="/service/deepl", tags=["deepl"]) +app.include_router(translate.router, prefix="/service/translate", tags=["translate"]) app.include_router(location.router, prefix="/service/location", tags=["ipinfo"]) check_and_create_table() diff --git a/routers/deepl.py b/routers/deepl.py deleted file mode 100644 index 6cc202f..0000000 --- a/routers/deepl.py +++ /dev/null @@ -1,19 +0,0 @@ -from fastapi import APIRouter, HTTPException - -from service.deepl import translate, LangCode - -router = APIRouter() - - -@router.post("/") -async def root_translate( - content: str, - source: LangCode | str | None, - target: LangCode | str | None -): - res = translate(content, source, target) - - if res is None: - raise HTTPException(status_code=500, detail="Translation failed") - - return res diff --git a/routers/translate.py b/routers/translate.py new file mode 100644 index 0000000..a91366d --- /dev/null +++ b/routers/translate.py @@ -0,0 +1,14 @@ +import os + +import deepl +from fastapi import APIRouter + +router = APIRouter() + +API_KEY = os.environ.get("DEEPL_KEY") +translator = deepl.Translator(API_KEY) + + +@router.post("/toKr") +async def translate(text: str): + return translator.translate_text(text, source_lang="EN", target_lang="KO")