-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.py
More file actions
30 lines (22 loc) · 681 Bytes
/
Copy pathAPI.py
File metadata and controls
30 lines (22 loc) · 681 Bytes
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
from fastapi import FastAPI
import requests
import joblib
import uvicorn
from data import get_data
import pandas as pd
import numpy as np
model = joblib.load('best_model.pkl')
encoder = joblib.load('label_encoder.pkl')
app = FastAPI()
@app.get('/')
def home():
return {'massage': 'Welcome'}
@app.post('/predict')
def predict(data : get_data):
df = pd.DataFrame(data.dict(), index=[0])
df.rename(columns={
"Temperature": "Temperature (C)",
"Wind_Speed": "Wind Speed (km/h)"
},inplace=True)
prediction = model.predict(df)[0]
return {"predicted_prognosis": encoder.inverse_transform([prediction])[0]}