Spaces:
Sleeping
Sleeping
| 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 | |
| async def convert_to_g2pk(request: TextRequest): | |
| try: | |
| result = g2p(request.text) | |
| return {"result": result} | |
| except Exception as e: | |
| return {"error": str(e)} | |
| async def healthcheck(): | |
| return {"status": "ok"} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("app:app", host="0.0.0.0", port=7860) |