Skip to content

Instantly share code, notes, and snippets.

@nongiach
Last active May 11, 2023 11:45
Show Gist options
  • Save nongiach/e2ef731462ef3ba6585db3f105598b57 to your computer and use it in GitHub Desktop.
Save nongiach/e2ef731462ef3ba6585db3f105598b57 to your computer and use it in GitHub Desktop.
Cerebrium script
# This script allows to simulate Cerebrium serverless in local for test purpose
# Author: @chaignc
# run me with
# uvicorn local:app --port 9000
from fastapi import FastAPI
from main import predict, PredictInput
import logging
import time
app = FastAPI()
logger = logging.basicConfig(level=logging.INFO)
# Define the predict endpoint
@app.post("/predict")
def predict_route(input_data: PredictInput):
start_time = time.time()
result = predict(input_data.dict(), "local", logger)
end_time = time.time()
run_time_ms = round((end_time - start_time) * 1000, 2)
return {"result": result, "run_time_ms": run_time_ms}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment