HosseinAhmadi commited on
Commit
bbf6791
·
verified ·
1 Parent(s): ece3b1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -121
app.py CHANGED
@@ -1,6 +1,7 @@
1
- # app.py - کاتب 2025 Edition — تم خفن، سریع و بدون ارور
2
  import gradio as gr
3
  from catboost import CatBoostRegressor
 
4
 
5
  # لود مدل (26 مگ = فوق سریع)
6
  model = CatBoostRegressor()
@@ -9,8 +10,8 @@ model.load_model("kaatib_v8_optimized.cbm")
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
@@ -22,136 +23,54 @@ def predict(area_type, area, rooms, neighborhood, elevator, parking, warehouse,
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(
@@ -160,10 +79,6 @@ with gr.Blocks(css=css, title="کاتب 2025 - قیمت آپارتمان تهر
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
 
169
  app.launch()
 
1
+ # app.py - کاتب 2025 — تم خفن، بدون ارور css، 100% کارکردنی روی HF Spaces
2
  import gradio as gr
3
  from catboost import CatBoostRegressor
4
+ import numpy as np
5
 
6
  # لود مدل (26 مگ = فوق سریع)
7
  model = CatBoostRegressor()
 
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 = model.predict([[
13
+ effective_area,
14
+ np.log1p(effective_area),
15
  rooms, age, 1 if age <= 5 else 0,
16
  neighborhood.strip(), int(elevator), int(parking), int(warehouse)
17
  ]])[0] / 1_000_000_000
 
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(css_html) # فقط این خط مهمه!
 
 
 
 
 
 
 
62
 
63
+ gr.HTML('<div class="header"><h1>کاتب</h1><p style="font-size:28px;margin:15px 0 5px">هوش مصنوعی پیش‌بینی قیمت مسکن تهران</p><p style="font-size:20px;color:#a0d8c8">۸۱,۰۰۰ آگهی واقعی دیوار ۱۴۰۴</p></div>')
64
+
65
+ area_type = gr.Radio(["متراژ مفید (معمول در دیوار)", "متراژ سندی"], value="متراژ مفید (معمول در دیوار)", label="نوع متراژ")
 
66
  with gr.Row():
67
  area = gr.Slider(40, 450, 90, step=1, label="متراژ")
68
  rooms = gr.Dropdown([1,2,3,4,5,6], value=3, label="تعداد خواب")
 
69
  neighborhood = gr.Textbox(placeholder="مثل: سعادت آباد، نیاوران، پونک، جردن...", label="محله")
 
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("پیش‌بینی قیمت", variant="primary").click(
 
79
  outputs=gr.Markdown()
80
  )
81
 
82
+ gr.HTML('<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"><p style="color:#d4af37;font-size:26px;margin:0">ساخته شده با افتخار در ایران</p></div>')
 
 
 
 
83
 
84
  app.launch()