Вы не можете выбрать более 25 тем
			Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
		
		
		
		
		
			
		
			
				
	
	
		
			35 строки
		
	
	
		
			869 B
		
	
	
	
		
			Python
		
	
			
		
		
	
	
			35 строки
		
	
	
		
			869 B
		
	
	
	
		
			Python
		
	
 | 
						|
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'})
 | 
						|
 | 
						|
@app.post('/api/prediction')
 | 
						|
def make_prediction(flat_id: int, item_features: dict):
 | 
						|
    prediction = app.handler.predict(flat_id, item_features)
 | 
						|
 | 
						|
    prediction_metric.observe(prediction)
 | 
						|
 | 
						|
    return ({
 | 
						|
             'price': prediction,
 | 
						|
             'flat_id': flat_id
 | 
						|
            })
 |