Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,60 @@
|
|
| 1 |
-
# app.py -
|
| 2 |
import gradio as gr
|
| 3 |
-
from catboost import CatBoostRegressor
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse, age):
|
|
|
|
| 11 |
effective_area = area if area_type == "متراژ مفید (معمول در دیوار)" else area * 0.87
|
| 12 |
-
pred =
|
| 13 |
-
effective_area,
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
neighborhood.strip(), int(elevator), int(parking), int(warehouse)
|
| 17 |
]])[0] / 1_000_000_000
|
| 18 |
|
| 19 |
return f"""
|
| 20 |
-
<div
|
| 21 |
-
|
| 22 |
-
|
| 23 |
</div>
|
| 24 |
"""
|
| 25 |
|
| 26 |
-
# تم 2025 خفن — با gr.HTML() کار میکنه
|
| 27 |
-
css_html = """
|
| 28 |
-
<style>
|
| 29 |
-
:root {--primary:#d4af37; --bg:#ffffff; --text:#1a1a1a; --gray:#666666;}
|
| 30 |
-
.gradio-container {
|
| 31 |
-
max-width: 920px !important; margin: 20px auto !important;
|
| 32 |
-
background: linear-gradient(135deg, #f8f9ff, #ffffff) !important;
|
| 33 |
-
border-radius: 28px !important; box-shadow: 0 20px 60px rgba(0,0,0,0.08) !important;
|
| 34 |
-
padding: 30px !important; direction: rtl !important;
|
| 35 |
-
font-family: 'Vazir', system-ui, sans-serif !important;
|
| 36 |
-
}
|
| 37 |
-
body {background: #f0f4f8 !important;}
|
| 38 |
-
.header {text-align:center; padding:50px 20px; background:linear-gradient(135deg,#0d2b1f,#1e4d38);
|
| 39 |
-
border-radius:24px; margin-bottom:35px; color:white;}
|
| 40 |
-
.header h1 {font-size:68px; margin:0; color:#d4af37; text-shadow:0 0 40px rgba(212,175,55,0.6);}
|
| 41 |
-
.gr-form {background:white !important; padding:24px !important; border-radius:20px !important;
|
| 42 |
-
box-shadow:0 8px 30px rgba(0,0,0,0.06) !important; margin-bottom:20px;}
|
| 43 |
-
label {color:var(--text) !important; font-weight:600 !important; font-size:16px !important;}
|
| 44 |
-
.gr-textbox, .gr-dropdown, .gr-slider > div {background:white !important; border:2px solid #e2e8f0 !important;
|
| 45 |
-
border-radius:16px !important; color:var(--gray) !important;}
|
| 46 |
-
.gr-textbox input::placeholder {color:#94a3b8 !important;}
|
| 47 |
-
.gr-button {background:linear-gradient(45deg,#d4af37,#f4d03f) !important; color:black !important;
|
| 48 |
-
font-weight:bold !important; font-size:22px !important; padding:18px !important;
|
| 49 |
-
border-radius:18px !important; box-shadow:0 10px 30px rgba(212,175,55,0.4) !important;
|
| 50 |
-
transition:all 0.3s !important;}
|
| 51 |
-
.gr-button:hover {transform:translateY(-4px) scale(1.02); box-shadow:0 20px 40px rgba(212,175,55,0.6) !important;}
|
| 52 |
-
.result-card {text-align:center; padding:40px; background:linear-gradient(135deg,#0d2b1f,#1e4d38);
|
| 53 |
-
border-radius:24px; border:4px solid var(--primary); color:white; animation:fadeIn 0.8s;}
|
| 54 |
-
.result-card h2 {font-size:52px; color:#d4af37; margin:10px 0;}
|
| 55 |
-
@keyframes fadeIn {from{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}
|
| 56 |
-
</style>
|
| 57 |
-
"""
|
| 58 |
-
|
| 59 |
-
# اپ اصلی — بدون css= در Blocks
|
| 60 |
with gr.Blocks(title="کاتب 2025 - قیمت آپارتمان تهران") as app:
|
| 61 |
-
gr.HTML(
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"], value="متراژ مفید (معمول در دیوار)", label="نوع متراژ")
|
| 66 |
-
with gr.Row():
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
with gr.Row():
|
| 71 |
-
elevator = gr.Checkbox(label="آسانسور", value=True)
|
| 72 |
-
parking = gr.Checkbox(label="پارکینگ", value=True)
|
| 73 |
-
warehouse = gr.Checkbox(label="انباری", value=True)
|
| 74 |
-
age = gr.Slider(0, 50, 8, step=1, label="سن بنا (سال)")
|
| 75 |
|
| 76 |
-
gr.Button("پیشبینی قیمت"
|
| 77 |
-
predict,
|
| 78 |
-
inputs=[area_type, area, rooms, neighborhood, elevator, parking, warehouse, age],
|
| 79 |
-
outputs=gr.Markdown()
|
| 80 |
-
)
|
| 81 |
|
| 82 |
-
gr.HTML('<div style="text-align:center;margin-top:50px;padding:35px;background:white;border-radius:20px;
|
| 83 |
|
| 84 |
app.launch()
|
|
|
|
| 1 |
+
# app.py - نسخه رایگان CPU basic — لود در ۱۰–۳۰ ثانیه، بدون ارور
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
model = None # مدل رو lazy load میکنیم
|
| 6 |
+
|
| 7 |
+
def load_model():
|
| 8 |
+
global model
|
| 9 |
+
if model is None:
|
| 10 |
+
from catboost import CatBoostRegressor
|
| 11 |
+
model = CatBoostRegressor()
|
| 12 |
+
model.load_model("kaatib_v8_optimized.cbm")
|
| 13 |
+
print("مدل کاتب لود شد!")
|
| 14 |
+
return model
|
| 15 |
|
| 16 |
def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse, age):
|
| 17 |
+
mdl = load_model() # فقط اینجا لود میشه
|
| 18 |
effective_area = area if area_type == "متراژ مفید (معمول در دیوار)" else area * 0.87
|
| 19 |
+
pred = mdl.predict([[
|
| 20 |
+
effective_area, np.log1p(effective_area), rooms, age,
|
| 21 |
+
1 if age <= 5 else 0, neighborhood.strip(),
|
| 22 |
+
int(elevator), int(parking), int(warehouse)
|
|
|
|
| 23 |
]])[0] / 1_000_000_000
|
| 24 |
|
| 25 |
return f"""
|
| 26 |
+
<div style="text-align:center;padding:40px;background:linear-gradient(135deg,#0d2b1f,#1e4d38);border-radius:24px;border:5px solid #d4af37;color:white">
|
| 27 |
+
<h1 style="font-size:56px;margin:15px 0;color:#d4af37">{pred:.2f} میلیارد تومان</h1>
|
| 28 |
+
<p style="font-size:22px">رنج واقعی: {(pred*0.88):.2f} – {(pred*1.15):.2f} میلیارد</p>
|
| 29 |
</div>
|
| 30 |
"""
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
with gr.Blocks(title="کاتب 2025 - قیمت آپارتمان تهران") as app:
|
| 33 |
+
gr.HTML("""
|
| 34 |
+
<style>
|
| 35 |
+
.gradio-container {max-width:920px;margin:20px auto;background:white;border-radius:28px;box-shadow:0 20px 60px rgba(0,0,0,0.1);padding:30px;direction:rtl;font-family:Vazir,system-ui}
|
| 36 |
+
body {background:#f0f4f8}
|
| 37 |
+
label {color:#1a1a1a;font-weight:600}
|
| 38 |
+
.gr-textbox,.gr-dropdown {background:white;border:2px solid #e2e8f0;border-radius:16px;color:#666}
|
| 39 |
+
.gr-textbox input::placeholder {color:#94a3b8}
|
| 40 |
+
.gr-button {background:linear-gradient(45deg,#d4af37,#f4d03f);color:black;font-weight:bold;font-size:22px;padding:18px;border-radius:18px}
|
| 41 |
+
.gr-button:hover {transform:translateY(-4px);box-shadow:0 15px 35px rgba(212,175,55,0.5)}
|
| 42 |
+
</style>
|
| 43 |
+
<div style="text-align:center;padding:50px;background:linear-gradient(135deg,#0d2b1f,#1e4d38);border-radius:24px;color:white">
|
| 44 |
+
<h1 style="font-size:68px;margin:0;color:#d4af37;text-shadow:0 0 40px #d4af3777">کاتب</h1>
|
| 45 |
+
<p style="font-size:28px;margin:10px">هوش مصنوعی پیشبینی قیمت مسکن تهران</p>
|
| 46 |
+
<p style="font-size:20px;color:#a0d8c8">۸۱,۰۰۰ آگهی واقعی دیوار ۱۴۰۴</p>
|
| 47 |
+
</div>
|
| 48 |
+
""")
|
| 49 |
|
| 50 |
area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"], value="متراژ مفید (معمول در دیوار)", label="نوع متراژ")
|
| 51 |
+
with gr.Row(): area = gr.Slider(40,450,90,step=1,label="متراژ"); rooms = gr.Dropdown([1,2,3,4,5,6],3,label="تعداد خواب")
|
| 52 |
+
neighborhood = gr.Textbox(placeholder="مثل: سعادت آباد، نیاوران، پونک...", label="محله")
|
| 53 |
+
with gr.Row(): elevator = gr.Checkbox("آسانسور",True); parking = gr.Checkbox("پارکینگ",True); warehouse = gr.Checkbox("انباری",True)
|
| 54 |
+
age = gr.Slider(0,50,8,step=1,label="سن بنا (سال)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
gr.Button("پیشبینی قیمت").click(predict, [area_type,area,rooms,neighborhood,elevator,parking,warehouse,age], gr.Markdown())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
gr.HTML('<div style="text-align:center;margin-top:50px;padding:35px;background:white;border-radius:20px;border:3px dashed #d4af37"><p style="color:#d4af37;font-size:26px">ساخته شده با افتخار در ایران</p></div>')
|
| 59 |
|
| 60 |
app.launch()
|