Spaces:
Sleeping
Sleeping
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_onnx import onnx_predictor | |
router = APIRouter(prefix="/model", tags=["Model"]) | |
async def get_question_tags(question: str): | |
# Get the prediction | |
original_sentence, predicted_tags = onnx_predictor.predict(question) | |
# Print the sentence and its predicted tags | |
print("Sentence:", original_sentence) | |
print("Predicted Tags:", predicted_tags) | |
return {"question_tags": predicted_tags} | |
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} | |
async def get_destinations_list_api(question: str, top_k:str): | |
# Get the prediction | |
original_sentence, question_tags = onnx_predictor.predict(question) | |
# Print the sentence and its predicted tags | |
print("Sentence:", original_sentence) | |
print("Predicted Tags:", question_tags) | |
# Get the prediction | |
question_tags = " ".join(question_tags) | |
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))) | |