|
|
import streamlit as st |
|
|
|
|
|
|
|
|
car_info = { |
|
|
'Toyota Camry': { |
|
|
'type': 'Petrol', |
|
|
'fuel_efficiency': '15 km/l', |
|
|
'interior': 'Leather seats, Touchscreen display', |
|
|
'exterior': 'Sleek design with alloy wheels', |
|
|
'body': 'Sedan', |
|
|
'tyres': '205/60 R16', |
|
|
'genuine_parts': ['Engine parts', 'Suspension', 'Brakes'], |
|
|
'price': 25000, |
|
|
'image_url': 'https://example.com/toyota_camry.jpg' |
|
|
}, |
|
|
'Tesla Model S': { |
|
|
'type': 'Electric', |
|
|
'battery': '100 kWh', |
|
|
'range': '370 miles', |
|
|
'charging_time': '1 hour fast charging', |
|
|
'interior': 'Minimalistic with touch screen dashboard', |
|
|
'exterior': 'Futuristic design with autopilot sensors', |
|
|
'body': 'Sedan', |
|
|
'tyres': '255/35 R20', |
|
|
'genuine_parts': ['Battery module', 'Motor', 'Charging port'], |
|
|
'price': 80000, |
|
|
'image_url': 'https://example.com/tesla_model_s.jpg' |
|
|
}, |
|
|
'Honda Civic': { |
|
|
'type': 'Petrol', |
|
|
'fuel_efficiency': '17 km/l', |
|
|
'interior': 'Fabric seats, 7-inch touchscreen', |
|
|
'exterior': 'Sporty design with LED headlights', |
|
|
'body': 'Sedan', |
|
|
'tyres': '215/55 R16', |
|
|
'genuine_parts': ['Brakes', 'Suspension', 'Steering'], |
|
|
'price': 23000, |
|
|
'image_url': 'https://example.com/honda_civic.jpg' |
|
|
} |
|
|
} |
|
|
|
|
|
def get_car_info(car_name): |
|
|
"""Fetch car details based on the car name.""" |
|
|
return car_info.get(car_name, None) |
|
|
|
|
|
def display_car_details(car_name): |
|
|
"""Display details of a single car.""" |
|
|
car_details = get_car_info(car_name) |
|
|
if not car_details: |
|
|
st.error("Car not found!") |
|
|
return |
|
|
|
|
|
|
|
|
if car_details.get('image_url'): |
|
|
st.image(car_details['image_url'], caption=car_name, width=300) |
|
|
|
|
|
st.subheader(f"**{car_name}**") |
|
|
st.write(f"**Price:** ${car_details['price']}") |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
|
st.markdown("**Specifications**") |
|
|
st.write(f"**Type:** {car_details['type']}") |
|
|
if car_details['type'] == 'Petrol': |
|
|
st.write(f"**Fuel Efficiency:** {car_details['fuel_efficiency']}") |
|
|
else: |
|
|
st.write(f"**Battery Capacity:** {car_details['battery']}") |
|
|
st.write(f"**Range:** {car_details['range']}") |
|
|
st.write(f"**Charging Time:** {car_details['charging_time']}") |
|
|
st.write(f"**Body Type:** {car_details['body']}") |
|
|
st.write(f"**Tyres:** {car_details['tyres']}") |
|
|
|
|
|
with col2: |
|
|
st.markdown("**Features**") |
|
|
st.write(f"**Interior:** {car_details['interior']}") |
|
|
st.write(f"**Exterior:** {car_details['exterior']}") |
|
|
st.markdown("**Genuine Parts:**") |
|
|
for part in car_details['genuine_parts']: |
|
|
st.write(f"- {part}") |
|
|
|
|
|
def compare_cars(selected_cars): |
|
|
"""Compare multiple cars side by side.""" |
|
|
if len(selected_cars) < 2: |
|
|
st.warning("Please select at least two cars to compare.") |
|
|
return |
|
|
|
|
|
st.subheader("π Car Comparison") |
|
|
comparison_data = {car: get_car_info(car) for car in selected_cars} |
|
|
|
|
|
col_headers = ["Feature"] + selected_cars |
|
|
comparison_table = [] |
|
|
|
|
|
|
|
|
features = ["Price", "Type", "Fuel Efficiency / Battery", "Range", "Charging Time", "Body Type", "Tyres"] |
|
|
|
|
|
for feature in features: |
|
|
row = [feature] |
|
|
for car in selected_cars: |
|
|
car_details = comparison_data[car] |
|
|
if feature == "Price": |
|
|
row.append(f"${car_details['price']}") |
|
|
elif feature == "Type": |
|
|
row.append(car_details["type"]) |
|
|
elif feature == "Fuel Efficiency / Battery": |
|
|
row.append(car_details.get("fuel_efficiency", car_details.get("battery", "N/A"))) |
|
|
elif feature == "Range": |
|
|
row.append(car_details.get("range", "N/A")) |
|
|
elif feature == "Charging Time": |
|
|
row.append(car_details.get("charging_time", "N/A")) |
|
|
elif feature == "Body Type": |
|
|
row.append(car_details["body"]) |
|
|
elif feature == "Tyres": |
|
|
row.append(car_details["tyres"]) |
|
|
comparison_table.append(row) |
|
|
|
|
|
st.table(comparison_table) |
|
|
|
|
|
def filter_cars_by_budget(budget): |
|
|
"""Filter cars based on user budget.""" |
|
|
filtered_cars = [car for car, details in car_info.items() if details['price'] <= budget] |
|
|
|
|
|
if not filtered_cars: |
|
|
st.warning("No cars found in this budget range.") |
|
|
return |
|
|
|
|
|
st.subheader(f"π Cars Under ${budget}") |
|
|
for car in filtered_cars: |
|
|
display_car_details(car) |
|
|
st.markdown("---") |
|
|
|
|
|
def main(): |
|
|
st.title("π Car Information & Comparison App") |
|
|
st.markdown("Find details about cars, compare models, and filter based on budget!") |
|
|
|
|
|
option = st.sidebar.radio("Choose an action", ["View Car Details", "Compare Cars", "Find Cars by Budget"]) |
|
|
|
|
|
if option == "View Car Details": |
|
|
car_list = list(car_info.keys()) |
|
|
selected_car = st.selectbox("Select a car model", car_list) |
|
|
display_car_details(selected_car) |
|
|
|
|
|
elif option == "Compare Cars": |
|
|
car_list = list(car_info.keys()) |
|
|
selected_cars = st.multiselect("Select cars to compare", car_list) |
|
|
compare_cars(selected_cars) |
|
|
|
|
|
elif option == "Find Cars by Budget": |
|
|
budget = st.slider("Select your budget ($)", min_value=20000, max_value=100000, step=5000) |
|
|
filter_cars_by_budget(budget) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |