import os import uvicorn from Destinations.get_destinations import (get_destinations_list, get_question_vector) from fastapi import APIRouter, FastAPI from fastapi.middleware.cors import CORSMiddleware from Model.model_predict import predictor router = APIRouter(prefix="/model", tags=["Model"]) @router.get("/get_question_tags/{question}") async def get_question_tags(question: str): # Get the prediction original_sentence, predicted_tags = predictor.predict(question) # Print the sentence and its predicted tags print("Sentence:", original_sentence) print("Predicted Tags:", predicted_tags) return {"question_tags": predicted_tags} @router.get("/get_destinations_list/{question_tags}/{top_k}") async def get_destinations_list_api(question_tags: str, top_k:str): # Get the prediction question_vector = get_question_vector(question_tags) destinations_list = get_destinations_list(question_vector, int(top_k)) print("destinations_list:", destinations_list) return {"destinations_list": destinations_list} app = FastAPI(docs_url="/") app.add_middleware( CORSMiddleware, allow_origins=['*'], allow_credentials=True, allow_methods=['*'], allow_headers=['*'], expose_headers=['*',] ) app.include_router(router) if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))