lec12
Этот коммит содержится в:
@@ -2,14 +2,13 @@ name: lec_app
|
||||
|
||||
services:
|
||||
price-predict:
|
||||
image: estate_model:1
|
||||
image: estate_model:2
|
||||
ports:
|
||||
- "8001:8000"
|
||||
volumes:
|
||||
- ./models:/models
|
||||
|
||||
|
||||
|
||||
requests:
|
||||
image: request_service:3
|
||||
deploy:
|
||||
@@ -19,7 +18,6 @@ services:
|
||||
delay: 5s
|
||||
|
||||
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus
|
||||
ports:
|
||||
@@ -38,4 +36,25 @@ services:
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
|
||||
|
||||
database:
|
||||
image: postgres:17.2
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
- POSTGRES_USER=admin
|
||||
- POSTGRES_PASSWORD=admin
|
||||
- POSTGRES_DB=my_db_name
|
||||
- PGDATA=/var/lib/postgresql/data/pgdata
|
||||
volumes:
|
||||
- "./database/data:/var/lib/postgresql/data"
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4
|
||||
ports:
|
||||
- 9091:80
|
||||
environment:
|
||||
- PGADMIN_DEFAULT_EMAIL=email@example.com
|
||||
- PGADMIN_DEFAULT_PASSWORD=admin
|
||||
volumes:
|
||||
- "./database/pgadmin:/var/lib/pgadmin"
|
||||
@@ -2,6 +2,8 @@
|
||||
import logging
|
||||
import pandas as pd
|
||||
import pickle as pkl
|
||||
import psycopg2
|
||||
from datetime import datetime
|
||||
|
||||
logger = logging.getLogger("uvicorn.error")
|
||||
class FastAPIHandler():
|
||||
@@ -14,7 +16,25 @@ class FastAPIHandler():
|
||||
except Exception as e:
|
||||
logger.error('Error loading model')
|
||||
|
||||
def predict(self, item_features:dict):
|
||||
def predict(self, flat_id, item_features:dict):
|
||||
item_df = pd.DataFrame(data=item_features, index=[0])
|
||||
prediction = self.model.predict(item_df)
|
||||
|
||||
db_cred = {"dbname": "my_db_name",
|
||||
"user": 'admin',
|
||||
"password": 'admin',
|
||||
"host": "database"}
|
||||
|
||||
db_conn = psycopg2.connect(**db_cred)
|
||||
cur = db_conn.cursor()
|
||||
|
||||
now = datetime.now()
|
||||
cur.execute(f"INSERT INTO public.features \
|
||||
(flat_id, ts, geo_lon, geo_lat, area) \
|
||||
VALUES ({flat_id}, '{now}', {item_features['geo_lon']}, {item_features['geo_lat']}, {item_features['area']});")
|
||||
cur.execute(f"INSERT INTO public.predictions \
|
||||
(flat_id, ts, price) VALUES ({flat_id}, '{now}', {prediction[0]});")
|
||||
|
||||
db_conn.commit()
|
||||
|
||||
return (prediction[0])
|
||||
@@ -24,7 +24,7 @@ def root_dir():
|
||||
|
||||
@app.post('/api/prediction')
|
||||
def make_prediction(flat_id: int, item_features: dict):
|
||||
prediction = app.handler.predict(item_features)
|
||||
prediction = app.handler.predict(flat_id, item_features)
|
||||
|
||||
prediction_metric.observe(prediction)
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ pandas
|
||||
pickle4
|
||||
scikit-learn
|
||||
requests
|
||||
prometheus_fastapi_instrumentator
|
||||
prometheus_fastapi_instrumentator
|
||||
psycopg2-binary
|
||||
Двоичные данные
lectures/lec12-database.pptx
Обычный файл
Двоичные данные
lectures/lec12-database.pptx
Обычный файл
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user