16 lines
431 B
Python
Executable File
16 lines
431 B
Python
Executable File
# server.py
|
|
from fastapi import FastAPI, Request
|
|
from paddlenlp import Taskflow
|
|
|
|
app = FastAPI()
|
|
|
|
# 모델 로드 (ChatGLM 등 대형 모델)
|
|
machine_translation = Taskflow("text2text_generation", source_lang="zh", target_lang="ko")
|
|
|
|
@app.post("/translate")
|
|
async def translate(request: Request):
|
|
body = await request.json()
|
|
text = body["text"]
|
|
result = machine_translation(text)
|
|
return {"translated_text": result}
|