# pricing_app.py import streamlit as st import requests import json # ========== PAGE CONFIG ========== st.set_page_config( page_title="Getaround Rental Pricing Prediction", #page_icon="🚗", layout="centered" ) # ========== CUSTOM CSS ========== st.markdown(""" """, unsafe_allow_html=True) # ========== API CONFIGURATION ========== API_URL = "https://sony9316-getaround-pricing-api.hf.space/predict" # ========== MAIN APP ========== st.markdown('

🚗 Prédiction du prix de location

', unsafe_allow_html=True) st.markdown("""
Remplissez les informations suivantes pour obtenir une estimation du prix de location par jour.
""", unsafe_allow_html=True) # ========== FORM INPUTS ========== with st.form("prediction_form"): st.markdown("### Caractéristiques du véhicule") # Car model model_key = st.selectbox( "Modèle de voiture", options=["Peugeot", "Audi", "BMW", "Volkswagen", "Mercedes", "Ford", "Opel", "Renault", "Toyota", "Nissan"], index=0 ) col1, col2 = st.columns(2) with col1: # Mileage mileage = st.number_input( "Kilométrage", min_value=0, max_value=500000, value=50000, step=1000 ) # Engine power engine_power = st.number_input( "Puissance moteur (CV)", min_value=50, max_value=500, value=100, step=10 ) # Fuel type fuel = st.selectbox( "Type de carburant", options=["diesel", "petrol", "electric", "hybrid"], index=0 ) with col2: # Paint color paint_color = st.selectbox( "Couleur", options=["black", "white", "grey", "blue", "red", "silver", "brown", "green"], index=0 ) # Car type car_type = st.selectbox( "Type de voiture", options=["sedan", "convertible", "suv", "coupe", "estate", "hatchback"], index=0 ) st.markdown("### Équipements et options") col1, col2 = st.columns(2) with col1: private_parking_available = st.checkbox("Parking privé disponible", value=True) has_gps = st.checkbox("GPS", value=True) has_air_conditioning = st.checkbox("Climatisation", value=True) automatic_car = st.checkbox("Boîte automatique", value=False) with col2: has_getaround_connect = st.checkbox("Getaround Connect", value=True) has_speed_regulator = st.checkbox("Régulateur de vitesse", value=True) winter_tires = st.checkbox("Pneus hiver", value=False) # Submit button submitted = st.form_submit_button("Prédire le prix optimal", use_container_width=True) # ========== API CALL AND RESULTS ========== if submitted: # Prepare the data for API call data = { "input": [ { "model_key": model_key, "mileage": mileage, "engine_power": engine_power, "fuel": fuel, "paint_color": paint_color, "car_type": car_type, "private_parking_available": private_parking_available, "has_gps": has_gps, "has_air_conditioning": has_air_conditioning, "automatic_car": automatic_car, "has_getaround_connect": has_getaround_connect, "has_speed_regulator": has_speed_regulator, "winter_tires": winter_tires, } ] } try: with st.spinner("Prédiction en cours..."): # Make API request response = requests.post(API_URL, json=data, timeout=30) if response.status_code == 200: result = response.json() predicted_price = result["prediction"][0] st.markdown(f"""

💰 Prix estimé

{predicted_price:.2f} € / jour

Prix de location journalier recommandé pour ce véhicule

""", unsafe_allow_html=True) # Display summary of inputs with st.expander("📋 Résumé des caractéristiques"): col1, col2 = st.columns(2) with col1: st.write(f"**Modèle:** {model_key}") st.write(f"**Kilométrage:** {mileage:,} km") st.write(f"**Puissance:** {engine_power} CV") st.write(f"**Carburant:** {fuel}") st.write(f"**Couleur:** {paint_color}") st.write(f"**Type:** {car_type}") with col2: st.write(f"**Parking privé:** {'Oui' if private_parking_available else 'Non'}") st.write(f"**GPS:** {'Oui' if has_gps else 'Non'}") st.write(f"**Climatisation:** {'Oui' if has_air_conditioning else 'Non'}") st.write(f"**Boîte auto:** {'Oui' if automatic_car else 'Non'}") st.write(f"**Connect:** {'Oui' if has_getaround_connect else 'Non'}") st.write(f"**Régulateur:** {'Oui' if has_speed_regulator else 'Non'}") else: st.markdown(f"""
Erreur API ({response.status_code}): {response.text}
""", unsafe_allow_html=True) except requests.exceptions.RequestException as e: st.markdown(f"""
Erreur de connexion: Impossible de contacter l'API de prédiction.
Détails: {str(e)}
""", unsafe_allow_html=True) except Exception as e: st.markdown(f"""
Erreur: {str(e)}
""", unsafe_allow_html=True) # ========== SIDEBAR INFO ========== with st.sidebar: st.markdown("## ℹ️ Information") st.markdown(""" Cette application utilise un modèle de machine learning pour prédire le prix optimal de location d'un véhicule basé sur ses caractéristiques. """) st.markdown("### 🔗 API") st.markdown(f"**Endpoint:** [Hugging Face Space]({API_URL.replace('/predict', '')})") st.markdown("### 📊 Modèle") st.markdown("Random Forest optimisé pour la prédiction de prix") with st.expander("🔧 Caractéristiques utilisées"): features = [ "Modèle de voiture", "Kilométrage", "Puissance moteur", "Type de carburant", "Couleur", "Type de véhicule", "Parking privé", "GPS", "Climatisation", "Boîte automatique", "Getaround Connect", "Régulateur de vitesse", "Pneus hiver" ] for i, feature in enumerate(features, 1): st.write(f"{i}. {feature}") # ========== FOOTER ========== st.markdown("---") st.markdown("""

Getaround Pricing Optimization - Powered by Machine Learning

""", unsafe_allow_html=True)