Spaces:
Sleeping
Sleeping
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) |