Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pickle
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# لود مدل (اگه مدل رو آپلود کردی)
|
| 9 |
+
if os.path.exists("kaatib_v8_best.pkl"):
|
| 10 |
+
model = pickle.load(open("kaatib_v8_best.pkl", "rb"))
|
| 11 |
+
else:
|
| 12 |
+
# اگه مدل نبود، یه پیام بده (موقتاً)
|
| 13 |
+
model = None
|
| 14 |
+
|
| 15 |
+
def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse, age):
|
| 16 |
+
if model is None:
|
| 17 |
+
return "مدل در حال لود شدن است، چند ثانیه صبر کنید..."
|
| 18 |
+
|
| 19 |
+
if area_type == "متراژ مفید (معمول در دیوار)":
|
| 20 |
+
effective_area = area
|
| 21 |
+
else:
|
| 22 |
+
effective_area = area * 0.87
|
| 23 |
+
|
| 24 |
+
df = pd.DataFrame([{
|
| 25 |
+
'area': effective_area,
|
| 26 |
+
'log_area': np.log1p(effective_area),
|
| 27 |
+
'rooms': rooms,
|
| 28 |
+
'age': age,
|
| 29 |
+
'is_new': 1 if age <= 5 else 0,
|
| 30 |
+
'neighborhood': neighborhood.strip(),
|
| 31 |
+
'elevator': elevator,
|
| 32 |
+
'parking': parking,
|
| 33 |
+
'warehouse': warehouse
|
| 34 |
+
}])
|
| 35 |
+
|
| 36 |
+
pred = model.predict(df)[0] / 1_000_000_000
|
| 37 |
+
lower = pred * 0.88
|
| 38 |
+
upper = pred * 1.15
|
| 39 |
+
|
| 40 |
+
return f"""
|
| 41 |
+
<div style="text-align:center; padding:30px; background: linear-gradient(135deg, #0d2b1f, #1a3d2e); border-radius:18px; border: 3px solid #d4af37; box-shadow: 0 10px 30px rgba(212,175,55,0.2);">
|
| 42 |
+
<h2 style="color:#d4af37; margin:0; font-size:28px;">پیشبینی کاتب</h2>
|
| 43 |
+
<h1 style="color:white; font-size:52px; margin:15px 0 10px;">{pred:.2f} میلیارد تومان</h1>
|
| 44 |
+
<p style="color:#b8d5cd; font-size:19px; margin:5px;">رنج واقعی بازار: {lower:.2f} – {upper:.2f} میلیارد</p>
|
| 45 |
+
</div>
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
css = """
|
| 49 |
+
.gradio-container {max-width: 920px !important; margin: 20px auto; background: linear-gradient(135deg, #0a1e15, #0f2b1f); border-radius: 28px; box-shadow: 0 25px 70px rgba(0,0,0,0.9); border: 1px solid #1e3d2f;}
|
| 50 |
+
body {background: #040a07;}
|
| 51 |
+
label, .gr-form label, .gr-radio label, .gr-checkbox label, .gr-slider label, .gr-textbox label, .gr-dropdown label {
|
| 52 |
+
color: black !important; font-weight: bold !important; background: rgba(255,255,255,0.95) !important; padding: 10px 18px !important; border-radius: 14px !important; box-shadow: 0 4px 12px rgba(0,0,0,0.2);}
|
| 53 |
+
.gr-radio, .gr-checkbox-group {background: white !important; border-radius: 14px !important; padding: 15px !important; border: 2px solid #d4af37;}
|
| 54 |
+
.gr-slider .track, .gr-dropdown {background: white !important; color: black !important;}
|
| 55 |
+
.gr-button {background: linear-gradient(45deg, #d4af37, #b8971a) !important; color: black !important; border: none !important; font-weight: bold !important; font-size: 20px !important; padding: 18px !important; border-radius: 16px !important; box-shadow: 0 8px 25px rgba(212,175,55,0.5);}
|
| 56 |
+
.gr-button:hover {transform: translateY(-4px); box-shadow: 0 15px 35px rgba(212,175,55,0.7);}
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
with gr.Blocks(css=css, title="کاتب - قیمت آپارتمان تهران ۱۴۰۴") as kaatib:
|
| 60 |
+
gr.HTML("""
|
| 61 |
+
<div style="text-align:center; padding:55px 20px; background: linear-gradient(135deg, #0d2b1f, #1e4d38); border-bottom: 5px solid #d4af37;">
|
| 62 |
+
<h1 style="font-size:62px; margin:0; color:#d4af37; text-shadow: 0 0 30px #d4af3777;">کاتب</h1>
|
| 63 |
+
<p style="font-size:30px; color:#b8d5cd; margin:15px 0 5px;">هوش مصنوعی پیشبینی قیمت مسکن تهران</p>
|
| 64 |
+
<p style="font-size:21px; color:#8fb8a2;">۸۱,۰۰۰ آگهی واقعی دیوار ۱۴۰۴</p>
|
| 65 |
+
</div>
|
| 66 |
+
""")
|
| 67 |
+
|
| 68 |
+
area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"], value="متراژ مفید (معمول در دیوار)", label="نوع متراژ وارد شده")
|
| 69 |
+
|
| 70 |
+
with gr.Row():
|
| 71 |
+
area = gr.Slider(40, 450, value=90, step=1, label="متراژ")
|
| 72 |
+
rooms = gr.Dropdown([1,2,3,4,5,6], value=3, label="تعداد خواب")
|
| 73 |
+
|
| 74 |
+
neighborhood = gr.Textbox(placeholder="مثل: سعادت آباد، نیاوران، زعفرانیه، جردن، پونک...", label="محله")
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
elevator = gr.Checkbox(label="آسانسور", value=True)
|
| 78 |
+
parking = gr.Checkbox(label="پارکینگ", value=True)
|
| 79 |
+
warehouse = gr.Checkbox(label="انباری", value=True)
|
| 80 |
+
|
| 81 |
+
age = gr.Slider(0, 50, value=8, step=1, label="سن بنا (سال)")
|
| 82 |
+
|
| 83 |
+
btn = gr.Button("پیشبینی قیمت", variant="primary", size="lg")
|
| 84 |
+
output = gr.Markdown()
|
| 85 |
+
|
| 86 |
+
btn.click(predict, inputs=[area_type, area, rooms, neighborhood, elevator, parking, warehouse, age], outputs=output)
|
| 87 |
+
|
| 88 |
+
gr.HTML("""
|
| 89 |
+
<div style="text-align:center; margin:50px 20px 30px; padding:30px; background: rgba(212,175,55,0.12); border-radius:18px; border: 2px dashed #d4af37;">
|
| 90 |
+
<p style="color:#d4af37; font-size:20px; margin:8px;">ساخته شده با افتخار در ایران ایران</p>
|
| 91 |
+
<p style="color:#b8d5cd; font-size:16px;">اولین مدل تماماً فارسی برای با��ار مسکن تهران</p>
|
| 92 |
+
</div>
|
| 93 |
+
""")
|
| 94 |
+
|
| 95 |
+
kaatib.launch()
|