File size: 2,282 Bytes
773fd8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
from datasets import load_dataset
import pandas as pd

@st.cache_data
def load_data():
    ds = load_dataset("Unit293/car_models_3887", split="train")
    df = pd.DataFrame(ds)
    df = df.rename(columns={
        "make": "Brand",
        "model": "Model",
        "year": "Year",
        "fuelType": "FuelType",
        "seats": "Seats",
        "transmission": "Transmission",
        "price": "Price"  # עדכן אם בעמודות יש שם אחר למחיר
    })
    return df

def compute_score(row, prefs):
    score = 0
    if row.get("Price", 1e9) <= prefs["budget"]:
        score += 1
    if pd.notna(row.get("Seats")) and row["Seats"] >= prefs["seats"]:
        score += 1
    if row.get("FuelType") in prefs["fuel"]:
        score += 1
    if prefs["offroad"] and row.get("OffroadUsage", 0) == 1:
        score += 1
    return score

df = load_data()

st.title("איזה רכב מתאים לך? 🚗")

prefs = dict()
prefs["budget"] = st.slider(
    "מה התקציב שלך?",
    int(df["Price"].min()) if "Price" in df else 50000,
    int(df["Price"].max()) if "Price" in df else 300000,
    int(df["Price"].median()) if "Price" in df else 150000,
    step=5000
)
prefs["seats"] = st.selectbox("כמה מקומות ישיבה?", sorted(df["Seats"].dropna().unique()))
prefs["fuel"] = st.multiselect("איזה סוג דלק מתאים לך?", sorted(df["FuelType"].dropna().unique()))
prefs["offroad"] = st.checkbox("צריך יכולת שטח?", False)

df["score"] = df.apply(lambda r: compute_score(r, prefs), axis=1)
result = df.sort_values(by=["score", "Year"], ascending=[False, False])
top3 = result.head(3)

st.subheader("המלצות עבורך (עם ציון התאמה):")
if top3.empty:
    st.write("לא נמצאו התאמות מתאימות")
else:
    st.table(top3[["Brand", "Model", "Year", "Price", "FuelType", "Seats", "score"]])

if st.button("צור תיאור רכב מותאם אישית"):
    desc = (f"הרכב האידאלי עבורך: תקציב עד {prefs['budget']}₪, "
            f"לפחות {prefs['seats']} מקומות ישיבה, סוגי דלק מועדפים {prefs['fuel']}, "
            f"{'מתאים לשטח' if prefs['offroad'] else 'מותאם לעיר בלבד'}.")
    st.write(desc)