-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (58 loc) · 1.43 KB
/
main.py
File metadata and controls
62 lines (58 loc) · 1.43 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from fastapi import FastAPI
from pydantic import BaseModel
import pickle
import pandas as pd
import tensorflow as tf
app=FastAPI()
class Asteroid(BaseModel):
a: float
e: float
i: float
om: float
w: float
q: float
ad: float
per_y: float
data_arc: float
condition_code: float
n_obs_used: int
H: float
spkid: int
sats: int
albedo: float
diameter_sigma: float
orbit_id: float
epoch: float
epoch_mjd: int
epoch_cal: int
ma: float
n: float
tp: float
per: float
moid: float
moid_ld: float
moid_jup: float
t_jup: float
sigma_e: float
sigma_a: float
sigma_q: float
sigma_i: float
sigma_om: float
sigma_w: float
sigma_ma: float
sigma_ad: float
sigma_n: float
sigma_tp: float
sigma_per: float
rms: float
with open('scaler1.pkl','rb') as f:
scaler1=pickle.load(f)
with open('scaler2.pkl','rb') as f:
scaler2=pickle.load(f)
model=tf.keras.models.load_model('model1.h5')
@app.post('/')
async def diameter_endpoint(item:Asteroid):
# return item
df=scaler1.transform(pd.DataFrame([item.dict().values()],columns=item.dict().keys()))
pred=scaler2.inverse_transform(model.predict(df))
return {"diameter":float(pred)}