Last active
May 11, 2023 11:45
-
-
Save nongiach/e2ef731462ef3ba6585db3f105598b57 to your computer and use it in GitHub Desktop.
Cerebrium script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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