Spaces:
No application file
No application file
App.py
#1
by
Rdad
- opened
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import lightgbm as lgb
|
| 4 |
+
import unicodedata
|
| 5 |
+
|
| 6 |
+
# 1. تحميل النموذج والبيانات
|
| 7 |
+
train_data = pd.read_csv('train_90.csv')
|
| 8 |
+
X_train = train_data.drop(columns=['price'])
|
| 9 |
+
y_train = train_data['price']
|
| 10 |
+
model = lgb.LGBMRegressor().fit(X_train, y_train)
|
| 11 |
+
|
| 12 |
+
# 2. تعيينات القوائم المنسدلة
|
| 13 |
+
property_types = ["شقة", "فيلا", "دور"]
|
| 14 |
+
cities = ["الرياض", "جدة", "الدمام"]
|
| 15 |
+
|
| 16 |
+
# 3. دالة التنبؤ
|
| 17 |
+
def predict_price(city, district, property_type, area, rooms, bathrooms):
|
| 18 |
+
try:
|
| 19 |
+
input_data = pd.DataFrame([{
|
| 20 |
+
'city': city,
|
| 21 |
+
'district': district,
|
| 22 |
+
'property_type': property_type,
|
| 23 |
+
'area': float(area),
|
| 24 |
+
'rooms': int(rooms),
|
| 25 |
+
'bathrooms': int(bathrooms)
|
| 26 |
+
}])
|
| 27 |
+
prediction = model.predict(input_data)[0]
|
| 28 |
+
return f"السعر المتوقع: {round(prediction, 2):,} ريال"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"خطأ: {str(e)}"
|
| 31 |
+
|
| 32 |
+
# 4. واجهة Gradio
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=predict_price,
|
| 35 |
+
inputs=[
|
| 36 |
+
gr.Dropdown(cities, label="المدينة"),
|
| 37 |
+
gr.Textbox(label="الحي"),
|
| 38 |
+
gr.Dropdown(property_types, label="نوع العقار"),
|
| 39 |
+
gr.Number(label="المساحة (م²)"),
|
| 40 |
+
gr.Number(label="عدد الغرف"),
|
| 41 |
+
gr.Number(label="عدد الحمامات")
|
| 42 |
+
],
|
| 43 |
+
outputs=gr.Textbox(label="النتيجة"),
|
| 44 |
+
title="تطبيق تقدير أسعار العقارات"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
iface.launch()
|