-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (43 loc) · 1 KB
/
main.py
File metadata and controls
56 lines (43 loc) · 1 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
import dill
import pandas as pd
from fastapi import FastAPI
from pydantic import BaseModel
with open('model/model.pkl', 'rb') as file:
model = dill.load(file)
app = FastAPI()
class Form(BaseModel):
session_id: str
client_id: str
visit_date: str
visit_time: str
visit_nuber: int
utm_source: str
utm_medium: str
utm_campaign: str
utm_adcontent: str
utm_keyword: str
device_category: str
device_os: str
device_brand: str
device_model: str
device_screen_resolution: str
device_browser: str
geo_country: str
geo_city: str
class Predict(BaseModel):
session_id: str
CR: int
@app.get('/status')
def status():
return {'status': 'ok'}
@app.get('/version')
def version():
return model['metadata']
@app.post('/predict', response_model=Predict)
def predict(form: Form):
df = pd.DataFrame.from_dict([form.model_dump()])
y = model['model'].predict(df)
return {
'session_id': form.session_id,
'CR': y[0]
}