Spaces:
Runtime error
Runtime error
done
Browse files- __pycache__/main.cpython-39.pyc +0 -0
- main.py +12 -8
__pycache__/main.cpython-39.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|
main.py
CHANGED
|
@@ -2,6 +2,8 @@ from fastapi import FastAPI
|
|
| 2 |
import pickle
|
| 3 |
import uvicorn
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
| 5 |
|
| 6 |
app = FastAPI(debug=True)
|
| 7 |
|
|
@@ -19,14 +21,16 @@ ml_model = load_pickle('my_model.pkl')
|
|
| 19 |
#Root endpoints
|
| 20 |
@app.get("/")
|
| 21 |
def root():
|
| 22 |
-
return {"API": "An API for
|
| 23 |
|
| 24 |
-
@app.
|
| 25 |
async def predict(data: dict):
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
model_output = ml_model.predict(
|
| 31 |
-
print('
|
| 32 |
-
|
|
|
|
|
|
|
|
|
| 2 |
import pickle
|
| 3 |
import uvicorn
|
| 4 |
import pandas as pd
|
| 5 |
+
import json
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
app = FastAPI(debug=True)
|
| 9 |
|
|
|
|
| 21 |
#Root endpoints
|
| 22 |
@app.get("/")
|
| 23 |
def root():
|
| 24 |
+
return {"API": "An API for AMES Prediction."}
|
| 25 |
|
| 26 |
+
@app.post('/predict')
|
| 27 |
async def predict(data: dict):
|
| 28 |
|
| 29 |
+
start = time.time()
|
| 30 |
+
data_ = pd.DataFrame(data)
|
| 31 |
+
print('Data: ', type(data_))
|
| 32 |
+
model_output = ml_model.predict(data_)
|
| 33 |
+
print('Predictions: ', 10 ** model_output)
|
| 34 |
+
end = time.time()
|
| 35 |
+
time_to_inference = end - start
|
| 36 |
+
return {'predict': list(10 ** model_output), 'time_to_inference': time_to_inference}
|