Andrey 5 месяцев назад
Родитель f01e753aa2
Сommit 82eaaf221f

@ -14,6 +14,8 @@
| 17.10.2024 | [Feature extraction. Настройка гиперпараметров](./lectures/lec7-feature_selection_hyperparams.odp) - [в формате pptx](./lectures/lec7-feature_selection_hyperparams.pptx) - код в [ноутбуке к mlflow](./assets/mlflow/research.ipynb) | | 17.10.2024 | [Feature extraction. Настройка гиперпараметров](./lectures/lec7-feature_selection_hyperparams.odp) - [в формате pptx](./lectures/lec7-feature_selection_hyperparams.pptx) - код в [ноутбуке к mlflow](./assets/mlflow/research.ipynb) |
| 24.10.2024 | [Архитекура сервиса. API](./lectures/lec8-api.odp) - [в формате pptx](./lectures/lec8-api.pptx) | | 24.10.2024 | [Архитекура сервиса. API](./lectures/lec8-api.odp) - [в формате pptx](./lectures/lec8-api.pptx) |
| 14.11.2024 | [Создание микросервиса](./lectures/lec9-webserver.pptx) | | 14.11.2024 | [Создание микросервиса](./lectures/lec9-webserver.pptx) |
| 19.11.2024 | [Docker compose](./lectures/lec10-docker_compose.pptx) |
| 21.11.2024 | [Мониторинг сервиса. Prometheus. Graphana](./lectures/lec11-monitoring.pptx) |
## <span style="color:red">Перенос занятий</span> ## <span style="color:red">Перенос занятий</span>

@ -0,0 +1,15 @@
name: lec_app
services:
price-predict:
image: estate_model:0
ports:
- "8001:8000"
volumes:
- ./models:/models
requests:
image: test_requests:2

@ -2,10 +2,22 @@
import random import random
from fastapi import FastAPI from fastapi import FastAPI
from api_handler import FastAPIHandler from api_handler import FastAPIHandler
from prometheus_fastapi_instrumentator import Instrumentator
from prometheus_client import Histogram, Gauge, Counter, Summary
app = FastAPI() app = FastAPI()
app.handler = FastAPIHandler() app.handler = FastAPIHandler()
instrumentator = Instrumentator()
instrumentator.instrument(app).expose(app)
prediction_metric = Histogram(
'prediction_metric_histogram',
'histogram of predicted prices',
buckets=(100000, 1000000, 3000000, 5000000, 15000000, 50000000, 100000000)
)
@app.get('/') @app.get('/')
def root_dir(): def root_dir():
return({'Hello': 'world'}) return({'Hello': 'world'})
@ -13,6 +25,9 @@ def root_dir():
@app.post('/api/prediction') @app.post('/api/prediction')
def make_prediction(flat_id: int, item_features: dict): def make_prediction(flat_id: int, item_features: dict):
prediction = app.handler.predict(item_features) prediction = app.handler.predict(item_features)
prediction_metric.observe(prediction)
return ({ return ({
'price': prediction, 'price': prediction,
'flat_id': flat_id 'flat_id': flat_id

@ -3,3 +3,5 @@ uvicorn
pandas pandas
pickle4 pickle4
scikit-learn scikit-learn
requests
prometheus_fastapi_instrumentator

@ -0,0 +1,11 @@
FROM python:3.11-slim
COPY . /app
WORKDIR /app
RUN pip install requests
CMD ["python3", "req.py"]
# docker build . --tag test_requests:0
# docker run test_requests:0

@ -0,0 +1,23 @@
import requests
import time
import random
time.sleep(3)
for i in range(50):
params = {'flat_id': i}
data = {
"geo_lat": 51.3153190612793,
"geo_lon": 37.920509338378906,
"region": 5952,
"building_type": 3,
"level": random.randint(1,20),
"levels": 9,
"rooms": 2,
"area": random.uniform(10, 200),
"kitchen_area": 10,
"object_type": 1,
"floor_level": "mid"
}
response = requests.post('http://localhost:8000/api/prediction', params=params, json=data)
time.sleep(4)
print(response.json())

Двоичные данные
lectures/lec10-docker_compose.pptx

Двоичный файл не отображается.

Двоичные данные
lectures/lec11-monitoring.pptx

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить