import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from src.hf import generate_response app = FastAPI() # for CORS origins = ['http://localhost:3000', 'http://localhost:5173', 'http://localhost:5174'] # middleware app.add_middleware( CORSMiddleware, allow_origins = origins, allow_credentials = True, allow_methods = ['*'], allow_headers = ['*'] ) @app.get("/") async def root(): return {"message": "Hello World"} @app.get("/book") async def root(): return {"book_name": "Hikayat Naga Terbang"} @app.post('/classify') async def classify_text(question:str): answer = generate_response(question) topic_label, score = answer return {"label": topic_label} if __name__ == '__main__': uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)