Spaces:
Runtime error
Runtime error
File size: 837 Bytes
35f858f a233326 35f858f dc10e9d 35f858f 0a6d7d4 35f858f a233326 35f858f a233326 35f858f a233326 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from fastapi import FastAPI
import pickle
import uvicorn
import pandas as pd
import json
import time
app = FastAPI(debug=True)
# Function to load pickle file
def load_pickle(filename):
with open(filename, 'rb') as file:
data = pickle.load(file)
return data
# Load pickle file
ml_model = load_pickle('my_model.pkl')
#Endpoints
#Root endpoints
@app.get("/")
def root():
return {"API": "An API for AMES Prediction."}
@app.post('/predict')
async def predict(data: dict):
start = time.time()
data_ = pd.DataFrame(data)
print('Data: ', type(data_))
model_output = ml_model.predict(data_)
print('Predictions: ', 10 ** model_output)
end = time.time()
time_to_inference = end - start
return {'predict': list(10 ** model_output), 'time_to_inference': time_to_inference}
|