File size: 4,952 Bytes
eb00844
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# -*- coding: utf-8 -*-
import gradio as gr
from model import Model

# Initialize model
model = Model("sgd_model_pipeline.joblib")


def predict_price(
    squere,
    dist_1,
    dist_2,
    dist_3,
    category_encoded,
    floor_,
    offer_type,
    series,
    condition,
    building_type,
    year
):
    """
    Make apartment price prediction based on input features.
    """
    # Create features dictionary
    features = {
        'squere': int(squere),
        'dist_1': float(dist_1),
        'dist_2': float(dist_2),
        'dist_3': float(dist_3),
        'CategoryEncoded': float(category_encoded),
        'floor_': str(floor_),
        'Тип предложения': offer_type,
        'Серия': series,
        'Состояние': condition,
        'dom': building_type,
        'year': int(year)
    }

    # Get prediction
    try:
        predicted_price = model.predict(features)
        return f"Predicted Price: ${predicted_price:,.2f} USD"
    except Exception as e:
        return f"Error: {str(e)}"


# Define dropdown options based on schema
offer_types = ['от агента', 'от собственника']

building_series = [
    'индивид. планировка',
    'элитка',
    '106 серия',
    'хрущевка',
    '106 серия улучшенная',
    '104 серия',
    '108 серия',
    '105 серия',
    '104 серия улучшенная',
    '105 серия улучшенная',
    'пентхаус',
    'малосемейка',
    'сталинка',
    '107 серия'
]

conditions = [
    'евроремонт',
    'под самоотделку (псо)',
    'хорошее',
    'среднее',
    'не достроено'
]

building_types = ['кирпичный', 'монолитный', 'панельный']


# Create Gradio interface
with gr.Blocks(theme=gr.themes.Ocean()) as demo:
    gr.Markdown("# Bishkek Apartment Price Prediction")
    gr.Markdown("Enter apartment details to get a price prediction")

    with gr.Row():
        with gr.Column():
            gr.Markdown("### Basic Information")
            squere = gr.Number(
                label="Area (square meters)",
                value=50,
                minimum=10,
                maximum=500
            )
            floor_ = gr.Textbox(
                label="Floor Number",
                value="1",
                placeholder="e.g., 1, 3, 6"
            )
            year = gr.Number(
                label="Building Year",
                value=2010,
                minimum=1950,
                maximum=2025
            )

            gr.Markdown("### Location Features")
            category_encoded = gr.Number(
                label="Category Encoded (mean square for location)",
                value=60.0
            )
            dist_1 = gr.Number(
                label="Distance 1 (km)",
                value=1.0,
                minimum=0
            )
            dist_2 = gr.Number(
                label="Distance 2 (km)",
                value=2.0,
                minimum=0
            )
            dist_3 = gr.Number(
                label="Distance 3 (km)",
                value=3.0,
                minimum=0
            )

        with gr.Column():
            gr.Markdown("### Building Characteristics")
            offer_type = gr.Dropdown(
                choices=offer_types,
                label="Offer Type",
                value=offer_types[0]
            )
            series = gr.Dropdown(
                choices=building_series,
                label="Building Series",
                value=building_series[0]
            )
            condition = gr.Dropdown(
                choices=conditions,
                label="Condition",
                value=conditions[0]
            )
            building_type = gr.Dropdown(
                choices=building_types,
                label="Building Type",
                value=building_types[0]
            )

    # Predict button and output
    with gr.Row():
        predict_btn = gr.Button("Predict Price", variant="primary", size="lg")

    with gr.Row():
        output = gr.Textbox(label="Prediction Result", scale=2)

    # Set up the prediction function
    predict_btn.click(
        fn=predict_price,
        inputs=[
            squere,
            dist_1,
            dist_2,
            dist_3,
            category_encoded,
            floor_,
            offer_type,
            series,
            condition,
            building_type,
            year
        ],
        outputs=output
    )

    # Example section
    gr.Markdown("---")
    gr.Markdown("### Example Values")
    gr.Markdown("""
    - **Area**: 60-80 sq meters (typical 2-room apartment)
    - **Floor**: 1-16 (depending on building)
    - **Year**: 1960-2024
    - **Distances**: 0.5-5 km to points of interest
    """)


if __name__ == "__main__":
    demo.launch(share=True)