import gradio as gr import joblib import numpy as np # Загрузка модели model = joblib.load('house_price_model.pkl') def predict_price(square, rooms): """Функция, которую обернёт Gradio""" input_data = np.array([[square, rooms]]) price = model.predict(input_data)[0] return f"{price:.0f} тыс. у.е." # Создаём интерфейс with gr.Blocks(title="Оценка дома", theme=gr.themes.Soft()) as demo: gr.Markdown("# 🏡 Предсказание цены дома с помощью Gradio") gr.Markdown("Введите параметры — модель линейной регрессии предскажет стоимость.") with gr.Row(): square_input = gr.Number(label="Площадь (м²)", value=80.0, minimum=10.0, maximum=200.0) rooms_input = gr.Slider(label="Количество комнат", minimum=1, maximum=5, step=1, value=3) price_output = gr.Textbox(label="Прогнозируемая цена", interactive=False) predict_btn = gr.Button("Рассчитать", variant="primary") predict_btn.click(fn=predict_price, inputs=[square_input, rooms_input], outputs=price_output) gr.Markdown("### Коэффициенты модели") gr.Markdown(f"- За 1 м²: {model.coef_[0]:.2f} тыс. у.е.\n- За 1 комнату: {model.coef_[1]:.2f} тыс. у.е.\n- База: {model.intercept_:.0f} тыс. у.е.") # Запуск demo.launch(server_name="0.0.0.0", server_port=7860, share=False)