Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,168 @@
|
|
| 1 |
-
# app.py -
|
| 2 |
import gradio as gr
|
| 3 |
from catboost import CatBoostRegressor
|
| 4 |
|
| 5 |
-
# لود مدل
|
| 6 |
model = CatBoostRegressor()
|
| 7 |
model.load_model("kaatib_v8_optimized.cbm")
|
| 8 |
|
| 9 |
def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse, age):
|
| 10 |
effective_area = area if area_type == "متراژ مفید (معمول در دیوار)" else area * 0.87
|
| 11 |
pred = model.predict([[
|
| 12 |
-
effective_area,
|
| 13 |
__import__("numpy").log1p(effective_area),
|
| 14 |
-
rooms,
|
| 15 |
-
|
| 16 |
-
1 if age <= 5 else 0,
|
| 17 |
-
neighborhood.strip(),
|
| 18 |
-
elevator,
|
| 19 |
-
parking,
|
| 20 |
-
warehouse
|
| 21 |
]])[0] / 1_000_000_000
|
| 22 |
|
| 23 |
return f"""
|
| 24 |
-
<div
|
| 25 |
-
|
| 26 |
-
|
| 27 |
</div>
|
| 28 |
"""
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
gr.HTML("""
|
| 32 |
-
<div
|
| 33 |
-
<h1
|
| 34 |
-
<p style="font-size:28px;
|
| 35 |
-
<p style="font-size:20px;color:#
|
| 36 |
</div>
|
| 37 |
""")
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
-
area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"],
|
|
|
|
|
|
|
| 41 |
with gr.Row():
|
| 42 |
area = gr.Slider(40, 450, 90, step=1, label="متراژ")
|
| 43 |
rooms = gr.Dropdown([1,2,3,4,5,6], value=3, label="تعداد خواب")
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
with gr.Row():
|
| 46 |
elevator = gr.Checkbox(label="آسانسور", value=True)
|
| 47 |
parking = gr.Checkbox(label="پارکینگ", value=True)
|
| 48 |
warehouse = gr.Checkbox(label="انباری", value=True)
|
|
|
|
| 49 |
age = gr.Slider(0, 50, 8, step=1, label="سن بنا (سال)")
|
| 50 |
|
| 51 |
-
gr.Button("پیشبینی قیمت").click(
|
| 52 |
predict,
|
| 53 |
inputs=[area_type, area, rooms, neighborhood, elevator, parking, warehouse, age],
|
| 54 |
outputs=gr.Markdown()
|
| 55 |
)
|
| 56 |
|
| 57 |
gr.HTML("""
|
| 58 |
-
<div style="text-align:center;margin-top:50px;padding:
|
| 59 |
-
<p style="color:#d4af37;font-size:
|
| 60 |
</div>
|
| 61 |
""")
|
| 62 |
|
|
|
|
| 1 |
+
# app.py - کاتب 2025 Edition — تم خفن، سریع و بدون ارور
|
| 2 |
import gradio as gr
|
| 3 |
from catboost import CatBoostRegressor
|
| 4 |
|
| 5 |
+
# لود مدل (26 مگ = فوق سریع)
|
| 6 |
model = CatBoostRegressor()
|
| 7 |
model.load_model("kaatib_v8_optimized.cbm")
|
| 8 |
|
| 9 |
def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse, age):
|
| 10 |
effective_area = area if area_type == "متراژ مفید (معمول در دیوار)" else area * 0.87
|
| 11 |
pred = model.predict([[
|
| 12 |
+
effective_area,
|
| 13 |
__import__("numpy").log1p(effective_area),
|
| 14 |
+
rooms, age, 1 if age <= 5 else 0,
|
| 15 |
+
neighborhood.strip(), int(elevator), int(parking), int(warehouse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
]])[0] / 1_000_000_000
|
| 17 |
|
| 18 |
return f"""
|
| 19 |
+
<div class="result-card">
|
| 20 |
+
<h2>{pred:.2f} میلیارد تومان</h2>
|
| 21 |
+
<p>رنج واقعی بازار: {(pred*0.88):.2f} – {(pred*1.15):.2f} میلیارد</p>
|
| 22 |
</div>
|
| 23 |
"""
|
| 24 |
|
| 25 |
+
# تم 2025 — سفید + نئون طلایی
|
| 26 |
+
css = """
|
| 27 |
+
<style>
|
| 28 |
+
:root {
|
| 29 |
+
--primary: #d4af37;
|
| 30 |
+
--bg: #ffffff;
|
| 31 |
+
--text: #1a1a1a;
|
| 32 |
+
--gray: #666666;
|
| 33 |
+
}
|
| 34 |
+
.gradio-container {
|
| 35 |
+
max-width: 920px !important;
|
| 36 |
+
margin: 20px auto !important;
|
| 37 |
+
background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%) !important;
|
| 38 |
+
border-radius: 28px !important;
|
| 39 |
+
box-shadow: 0 20px 60px rgba(0,0,0,0.08) !important;
|
| 40 |
+
padding: 30px !important;
|
| 41 |
+
direction: rtl !important;
|
| 42 |
+
font-family: 'Vazir', system-ui, sans-serif !important;
|
| 43 |
+
}
|
| 44 |
+
body {background: #f0f4f8 !important;}
|
| 45 |
+
|
| 46 |
+
/* هدر خفن */
|
| 47 |
+
.header {
|
| 48 |
+
text-align: center;
|
| 49 |
+
padding: 50px 20px;
|
| 50 |
+
background: linear-gradient(135deg, #0d2b1f 0%, #1e4d38 100%);
|
| 51 |
+
border-radius: 24px;
|
| 52 |
+
margin-bottom: 35px;
|
| 53 |
+
color: white;
|
| 54 |
+
}
|
| 55 |
+
.header h1 {
|
| 56 |
+
font-size: 68px;
|
| 57 |
+
margin: 0;
|
| 58 |
+
color: #d4af37;
|
| 59 |
+
text-shadow: 0 0 40px rgba(212,175,55,0.6);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* کارتهای ورودی */
|
| 63 |
+
.gr-form {
|
| 64 |
+
background: white !important;
|
| 65 |
+
padding: 24px !important;
|
| 66 |
+
border-radius: 20px !important;
|
| 67 |
+
box-shadow: 0 8px 30px rgba(0,0,0,0.06) !important;
|
| 68 |
+
margin-bottom: 20px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* لیبلها */
|
| 72 |
+
label {
|
| 73 |
+
color: var(--text) !important;
|
| 74 |
+
font-weight: 600 !important;
|
| 75 |
+
font-size: 16px !important;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/* باکسها */
|
| 79 |
+
.gr-textbox, .gr-dropdown, .gr-slider > div {
|
| 80 |
+
background: white !important;
|
| 81 |
+
border: 2px solid #e2e8f0 !important;
|
| 82 |
+
border-radius: 16px !important;
|
| 83 |
+
color: var(--gray) !important;
|
| 84 |
+
}
|
| 85 |
+
.gr-textbox input::placeholder {color: #94a3b8 !important;}
|
| 86 |
+
|
| 87 |
+
/* چکباکس و رادیو */
|
| 88 |
+
.gr-checkbox, .gr-radio {
|
| 89 |
+
background: white !important;
|
| 90 |
+
border: 2px solid var(--primary) !important;
|
| 91 |
+
border-radius: 12px !important;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/* دکمه طلایی با انیمیشن */
|
| 95 |
+
.gr-button {
|
| 96 |
+
background: linear-gradient(45deg, #d4af37, #f4d03f) !important;
|
| 97 |
+
color: black !important;
|
| 98 |
+
font-weight: bold !important;
|
| 99 |
+
font-size: 22px !important;
|
| 100 |
+
padding: 18px !important;
|
| 101 |
+
border-radius: 18px !important;
|
| 102 |
+
box-shadow: 0 10px 30px rgba(212,175,55,0.4) !important;
|
| 103 |
+
transition: all 0.3s ease !important;
|
| 104 |
+
}
|
| 105 |
+
.gr-button:hover {
|
| 106 |
+
transform: translateY(-4px) scale(1.02);
|
| 107 |
+
box-shadow: 0 20px 40px rgba(212,175,55,0.6) !important;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/* نتیجه */
|
| 111 |
+
.result-card {
|
| 112 |
+
text-align: center;
|
| 113 |
+
padding: 40px;
|
| 114 |
+
background: linear-gradient(135deg, #0d2b1f, #1e4d38);
|
| 115 |
+
border-radius: 24px;
|
| 116 |
+
border: 4px solid var(--primary);
|
| 117 |
+
color: white;
|
| 118 |
+
animation: fadeIn 0.8s ease;
|
| 119 |
+
}
|
| 120 |
+
.result-card h2 {
|
| 121 |
+
font-size: 52px;
|
| 122 |
+
color: #d4af37;
|
| 123 |
+
margin: 10px 0;
|
| 124 |
+
}
|
| 125 |
+
@keyframes fadeIn {from {opacity:0; transform:translateY(20px)} to {opacity:1; transform:translateY(0)}}
|
| 126 |
+
</style>
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
with gr.Blocks(css=css, title="کاتب 2025 - قیمت آپارتمان تهران") as app:
|
| 130 |
+
gr.HTML(css)
|
| 131 |
+
|
| 132 |
gr.HTML("""
|
| 133 |
+
<div class="header">
|
| 134 |
+
<h1>کاتب</h1>
|
| 135 |
+
<p style="font-size:28px;margin:15px 0 5px">هوش مصنوعی پیشبینی قیمت مسکن تهران</p>
|
| 136 |
+
<p style="font-size:20px;color:#a0d8c8">۸۱,۰۰۰ آگهی واقعی دیوار ۱۴۰۴</p>
|
| 137 |
</div>
|
| 138 |
""")
|
| 139 |
|
| 140 |
with gr.Row():
|
| 141 |
+
area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"],
|
| 142 |
+
value="متراژ مفید (معمول در دیوار)", label="نوع متراژ")
|
| 143 |
+
|
| 144 |
with gr.Row():
|
| 145 |
area = gr.Slider(40, 450, 90, step=1, label="متراژ")
|
| 146 |
rooms = gr.Dropdown([1,2,3,4,5,6], value=3, label="تعداد خواب")
|
| 147 |
+
|
| 148 |
+
neighborhood = gr.Textbox(placeholder="مثل: سعادت آباد، نیاوران، پونک، جردن...", label="محله")
|
| 149 |
+
|
| 150 |
with gr.Row():
|
| 151 |
elevator = gr.Checkbox(label="آسانسور", value=True)
|
| 152 |
parking = gr.Checkbox(label="پارکینگ", value=True)
|
| 153 |
warehouse = gr.Checkbox(label="انباری", value=True)
|
| 154 |
+
|
| 155 |
age = gr.Slider(0, 50, 8, step=1, label="سن بنا (سال)")
|
| 156 |
|
| 157 |
+
gr.Button("پیشبینی قیمت", variant="primary").click(
|
| 158 |
predict,
|
| 159 |
inputs=[area_type, area, rooms, neighborhood, elevator, parking, warehouse, age],
|
| 160 |
outputs=gr.Markdown()
|
| 161 |
)
|
| 162 |
|
| 163 |
gr.HTML("""
|
| 164 |
+
<div style="text-align:center;margin-top:50px;padding:35px;background:white;border-radius:20px;box-shadow:0 8px 30px rgba(0,0,0,0.08);border:2px dashed #d4af37">
|
| 165 |
+
<p style="color:#d4af37;font-size:26px;margin:0">ساخته شده با افتخار در ایران</p>
|
| 166 |
</div>
|
| 167 |
""")
|
| 168 |
|