File size: 1,039 Bytes
55ef0a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9af5d71
 
347f4f4
 
 
 
9af5d71
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)