Spaces:
Configuration error
Configuration error
| import streamlit as st | |
| from datasets import load_dataset | |
| import pandas as pd | |
| 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) | |