g2pk-server / app.py
daeunn's picture
Update app.py
347f4f4 verified
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
import sys
import os
# enhanced_g2pk.py ๊ฒฝ๋กœ ์ถ”๊ฐ€
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'model'))
from enhanced_g2pk import EnhancedG2p
app = FastAPI()
# CORS ์„ค์ • - ํ—ˆ๊น…ํŽ˜์ด์Šค ๋„๋ฉ”์ธ๋งŒ ํ—ˆ์šฉ
app.add_middleware(
CORSMiddleware,
allow_origins=["https://speako-frontend.hf.space"], # ๋ฐฐํฌ๋œ ํ”„๋ก ํŠธ์—”๋“œ๋งŒ ํ—ˆ์šฉ
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# G2P ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
g2p = EnhancedG2p()
class TextRequest(BaseModel):
text: str
@app.post("/g2pk")
async def convert_to_g2pk(request: TextRequest):
try:
result = g2p(request.text)
return {"result": result}
except Exception as e:
return {"error": str(e)}
@app.get("/healthcheck")
async def healthcheck():
return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("app:app", host="0.0.0.0", port=7860)