Spaces:
Runtime error
Runtime error
Download main.py from xValentim/ames_model: direct link, hf CLI and curl.
- Browser
- Download file 837 Bytes
-
https://huggingface.co/spaces/xValentim/ames_model/resolve/main/main.py
- Command line
-
hf download hf://spaces/xValentim/ames_model/main.py
-
curl -L -o main.py https://huggingface.co/spaces/xValentim/ames_model/resolve/main/main.py
837 Bytes
| 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 | |
| def root(): | |
| return {"API": "An API for AMES Prediction."} | |
| 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} | |