lec 10,11
Этот коммит содержится в:
@@ -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) |
|
||||
| 24.10.2024 | [Архитекура сервиса. API](./lectures/lec8-api.odp) - [в формате pptx](./lectures/lec8-api.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>
|
||||
|
||||
15
assets/service/compose.yml
Обычный файл
15
assets/service/compose.yml
Обычный файл
@@ -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
|
||||
from fastapi import FastAPI
|
||||
from api_handler import FastAPIHandler
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from prometheus_client import Histogram, Gauge, Counter, Summary
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
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('/')
|
||||
def root_dir():
|
||||
return({'Hello': 'world'})
|
||||
@@ -13,6 +25,9 @@ def root_dir():
|
||||
@app.post('/api/prediction')
|
||||
def make_prediction(flat_id: int, item_features: dict):
|
||||
prediction = app.handler.predict(item_features)
|
||||
|
||||
prediction_metric.observe(prediction)
|
||||
|
||||
return ({
|
||||
'price': prediction,
|
||||
'flat_id': flat_id
|
||||
|
||||
@@ -2,4 +2,6 @@ fastapi
|
||||
uvicorn
|
||||
pandas
|
||||
pickle4
|
||||
scikit-learn
|
||||
scikit-learn
|
||||
requests
|
||||
prometheus_fastapi_instrumentator
|
||||
11
assets/service/requests/Dockerfile
Обычный файл
11
assets/service/requests/Dockerfile
Обычный файл
@@ -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
|
||||
23
assets/service/requests/req.py
Обычный файл
23
assets/service/requests/req.py
Обычный файл
@@ -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/lec10-docker_compose.pptx
Обычный файл
Двоичный файл не отображается.
Двоичные данные
lectures/lec11-monitoring.pptx
Обычный файл
Двоичные данные
lectures/lec11-monitoring.pptx
Обычный файл
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user