Download app.py from dewiri/app.py: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/dewiri/app.py/resolve/main/app.py
- Command line
-
hf download hf://dewiri/app.py/app.py
-
curl -L -o app.py https://huggingface.co/dewiri/app.py/resolve/main/app.py
1.29 kB
| import streamlit as st | |
| import joblib | |
| import pandas as pd | |
| # Load the trained model | |
| model_path = "random_forest_model.pkl" | |
| model = joblib.load(model_path) | |
| # Title of the web app | |
| st.title("Car Price Prediction") | |
| # Input fields for user | |
| brand = st.text_input("Brand", "BMW") | |
| model_name = st.text_input("Model", "320i") | |
| year = st.number_input("Year", min_value=2000, max_value=2024, value=2018) | |
| mileage = st.number_input("Mileage (in km)", min_value=0, max_value=500000, value=50000) | |
| fuel_type = st.selectbox("Fuel Type", ["Petrol", "Diesel", "Hybrid", "Electric"]) | |
| engine_size = st.number_input("Engine Size (in liters)", min_value=0.5, max_value=6.0, value=2.0) | |
| # Prediction function | |
| def predict_price(brand, model_name, year, mileage, fuel_type, engine_size): | |
| # Create a DataFrame for input | |
| input_data = pd.DataFrame([[brand, model_name, year, mileage, fuel_type, engine_size]], | |
| columns=["Brand", "Model", "Year", "Mileage", "Fuel Type", "Engine Size"]) | |
| # Make prediction | |
| prediction = model.predict(input_data) | |
| return f"Estimated Price: {prediction[0]:,.2f} €" | |
| # Button to make a prediction | |
| if st.button("Predict Price"): | |
| result = predict_price(brand, model_name, year, mileage, fuel_type, engine_size) | |
| st.success(result) |