Spaces:
Sleeping
Sleeping
Mise à jour documentation et construction de l'interrogation du web service de tarif
Browse files
README.md
CHANGED
|
@@ -11,9 +11,9 @@ pinned: false
|
|
| 11 |
short_description: Streamlit template space
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 11 |
short_description: Streamlit template space
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Bienvenue sur l'application Streamlit pour le projet Get Around
|
| 15 |
|
| 16 |
+
Editer `getaround/app/app.py` pour adapter l'application à vos souhaits.
|
| 17 |
|
| 18 |
+
Pour toute question, veuillez vous diriger vers la [documentation](https://docs.streamlit.io) and le [
|
| 19 |
+
forum de la communauté](https://discuss.streamlit.io).
|
app.py
CHANGED
|
@@ -1,155 +1,175 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
import plotly.
|
| 5 |
-
import
|
| 6 |
-
import
|
| 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 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
st.
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
###
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
import plotly.graph_objects as go
|
| 6 |
+
import numpy as np
|
| 7 |
+
import requests
|
| 8 |
+
# ======================================================
|
| 9 |
+
# 🌐 API Pricing HF
|
| 10 |
+
# ======================================================
|
| 11 |
+
|
| 12 |
+
API_URL = "https://pradelf-getaround-api.hf.space/predict"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class RentalFeatures(BaseModel):
|
| 16 |
+
model_key: str = "Peugeot"
|
| 17 |
+
mileage: int = 0
|
| 18 |
+
engine_power: int = 100
|
| 19 |
+
fuel: str = "petrol"
|
| 20 |
+
paint_color: str = "black"
|
| 21 |
+
car_type: str = "sedan"
|
| 22 |
+
private_parking_available: int = 1
|
| 23 |
+
has_gps: int = 0
|
| 24 |
+
has_air_conditioning: int = 0
|
| 25 |
+
automatic_car: int = 0
|
| 26 |
+
has_getaround_connect: int = 0
|
| 27 |
+
has_speed_regulator: int = 0
|
| 28 |
+
winter_tires: int = 0
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def call_pricing_api(featRentalFeatures: RentalFeatures):
|
| 33 |
+
"""
|
| 34 |
+
Appelle l'API FastAPI déployée sur Hugging Face.
|
| 35 |
+
Retourne le prix prédit (float) ou None en cas d'erreur.
|
| 36 |
+
"""
|
| 37 |
+
payload = {"input": [featRentalFeatures.model_dump()]}
|
| 38 |
+
try:
|
| 39 |
+
resp = requests.post(API_URL, json=payload, timeout=10)
|
| 40 |
+
resp.raise_for_status()
|
| 41 |
+
data = resp.json()
|
| 42 |
+
if "prediction" in data and len(data["prediction"]) > 0:
|
| 43 |
+
return float(data["prediction"][0]), payload, data
|
| 44 |
+
else:
|
| 45 |
+
st.error("Réponse API inattendue : clé 'prediction' absente.")
|
| 46 |
+
return None, payload, data
|
| 47 |
+
except Exception as e:
|
| 48 |
+
st.error(f"Erreur lors de l'appel à l'API : {e}")
|
| 49 |
+
return None, payload, None
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
### CONFIG
|
| 53 |
+
st.set_page_config(page_title="Location Voiture", page_icon="💸", layout="wide")
|
| 54 |
+
|
| 55 |
+
### TITLE AND TEXT
|
| 56 |
+
st.title("Tableau de bord de Get Around")
|
| 57 |
+
|
| 58 |
+
st.markdown("""
|
| 59 |
+
Ce site représente le **dashboard** destiné à aider l’équipe Produit pour appréhender l'introduction
|
| 60 |
+
de la nouvelle fonctionnalité consistant en l'implémentation d'un **délai minimum entre deux locations**.<br/>
|
| 61 |
+
Un véhicule ne sera pas affiché dans les résultats de recherche si les heures de check-in
|
| 62 |
+
ou de check-out demandées sont trop proches d’une location déjà existante.<br/>
|
| 63 |
+
|
| 64 |
+
Grâce à ce site, l'équipe produit pourra répondre aux questions suivantes :<br/>
|
| 65 |
+
- quelle doit être la durée minimale du délai entre deux locations ?
|
| 66 |
+
- faut-il activer cette fonctionnalité pour tous les véhicules ou uniquement pour les véhicules Connect ?
|
| 67 |
+
- Quelle part des revenus des propriétaires serait potentiellement affectée par cette fonctionnalité ?
|
| 68 |
+
- Combien de locations seraient impactées en fonction du seuil et du périmètre choisis ?
|
| 69 |
+
- À quelle fréquence les conducteurs sont-ils en retard pour le check-in suivant ? Quel est l’impact pour le conducteur suivant ?
|
| 70 |
+
- Combien de situations problématiques seraient résolues selon le seuil et le périmètre retenus ?
|
| 71 |
+
|
| 72 |
+
La documentation du web serveur de fonctions est déploiée sur l'url : [https://pradelf-getaround-api.hf.space/docs](https://pradelf-getaround-api.hf.space/docs) """)
|
| 73 |
+
### LOAD DATA
|
| 74 |
+
DATA_PRICING = "/app/Data/get_around_pricing_project.csv"
|
| 75 |
+
DATA_PRICING_HF = "https://huggingface.co/datasets/pradelf/getaround-dataset/blob/main/get_around_pricing_project.csv"
|
| 76 |
+
|
| 77 |
+
DATA_ANALYSIS = "/app/Data/get_around_delay_analysis.csv"
|
| 78 |
+
DATA_DELAY_HF = "https://huggingface.co/datasets/pradelf/getaround-dataset/blob/main/get_around_delay_analysis.csv"
|
| 79 |
+
|
| 80 |
+
# usage d'un décorateur python pour ajouter des fonctionnalité
|
| 81 |
+
# : st.cache_data et st.cache_resource qui remplace st.cache qui va devenir obsolète.
|
| 82 |
+
# https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data
|
| 83 |
+
# https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource
|
| 84 |
+
@st.cache_data
|
| 85 |
+
def load_data(file, nrows, delimiter=","):
|
| 86 |
+
data = pd.read_csv(file, nrows=nrows, delimiter=delimiter)
|
| 87 |
+
# data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
|
| 88 |
+
# data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
|
| 89 |
+
return data
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
data_load_state = st.text("Chargement des données...")
|
| 93 |
+
data_pricing = load_data(DATA_PRICING_HF, 1000)
|
| 94 |
+
data_analysis = load_data(DATA_DELAY_HF, 1000, ";")
|
| 95 |
+
data_load_state.text(
|
| 96 |
+
""
|
| 97 |
+
) # change text from "Loading data..." to "" once the the load_data function has run
|
| 98 |
+
|
| 99 |
+
## Run the below code if the check is checked ✅
|
| 100 |
+
if st.checkbox("Montrer les données brutes sur le prix de location."):
|
| 101 |
+
st.subheader("Tarif de location")
|
| 102 |
+
st.write(data_pricing)
|
| 103 |
+
## Run the below code if the check is checked ✅
|
| 104 |
+
if st.checkbox("Montrer les données brutes sur l'analyse des retards de check-in."):
|
| 105 |
+
st.subheader("Retard de check-in")
|
| 106 |
+
st.write(data_analysis)
|
| 107 |
+
### SHOW GRAPH STREAMLIT
|
| 108 |
+
|
| 109 |
+
# price_per_model = data_pricing["price"]
|
| 110 |
+
# st.bar_chart(price_per_model)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
### SIDEBAR
|
| 114 |
+
st.sidebar.header("Tableau de bord GetAround")
|
| 115 |
+
st.sidebar.markdown("""
|
| 116 |
+
* GetAround projet
|
| 117 |
+
""")
|
| 118 |
+
e = st.sidebar.empty()
|
| 119 |
+
e.write("")
|
| 120 |
+
st.sidebar.write("GetAround Projet")
|
| 121 |
+
|
| 122 |
+
### EXPANDER
|
| 123 |
+
|
| 124 |
+
with st.expander(
|
| 125 |
+
"⏯️ Regardez cette vidéo d'une minute pour comprendre comment fonctionne Getaround."
|
| 126 |
+
):
|
| 127 |
+
st.video("https://youtu.be/3LyzwpGSfzE")
|
| 128 |
+
|
| 129 |
+
st.markdown("---")
|
| 130 |
+
|
| 131 |
+
#### CREATE TWO COLUMNS
|
| 132 |
+
col1, col2 = st.columns(2)
|
| 133 |
+
|
| 134 |
+
with col1:
|
| 135 |
+
# visu des widgets
|
| 136 |
+
st.markdown("Première colonne")
|
| 137 |
+
car_id = st.selectbox(
|
| 138 |
+
"Select a country you want to see all time sales",
|
| 139 |
+
data_analysis["car_id"].sort_values().unique(),
|
| 140 |
+
)
|
| 141 |
+
# intelligence et contrôle du widget
|
| 142 |
+
rental_canceled = data_analysis[data_analysis["state"] == "canceled"]
|
| 143 |
+
fig = px.histogram(
|
| 144 |
+
rental_canceled,
|
| 145 |
+
x="time_delta_with_previous_rental_in_minutes",
|
| 146 |
+
y="delay_at_checkout_in_minutes",
|
| 147 |
+
)
|
| 148 |
+
fig.update_layout(bargap=0.2)
|
| 149 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 150 |
+
|
| 151 |
+
with col2:
|
| 152 |
+
st.markdown("Seconde colonne")
|
| 153 |
+
with st.form("average_sales_per_country"):
|
| 154 |
+
model = st.selectbox(
|
| 155 |
+
"Sélectionnez un modèle de voiture pour voir le prix de location moyen",
|
| 156 |
+
data_pricing["model_key"].sort_values().unique(),
|
| 157 |
+
)
|
| 158 |
+
power = st.selectbox(
|
| 159 |
+
"Sélectionnez la puissance du moteur",
|
| 160 |
+
data_pricing["engine_power"].sort_values().unique(),
|
| 161 |
+
)
|
| 162 |
+
submit = st.form_submit_button("submit")
|
| 163 |
+
if submit:
|
| 164 |
+
model_select = data_pricing[data_pricing["model_key"] == model]
|
| 165 |
+
power_select = data_pricing[data_pricing["engine_power"] == power]
|
| 166 |
+
car_select=RentalFeatures(model_key=model, engine_power=power)
|
| 167 |
+
# avg_rental_price = data_pricing[model_select & power_select][
|
| 168 |
+
# "rental_price_per_day"
|
| 169 |
+
# ].mean()
|
| 170 |
+
rental_price = call_pricing_api(
|
| 171 |
+
car_select
|
| 172 |
+
)
|
| 173 |
+
# avg_rental_price = 0.0
|
| 174 |
+
st.metric("Prix de location moyen (en $)", np.round(rental_price, 2))
|
| 175 |
+
# exemple de véhicule du site avec les données : https://fr.getaround.com/location-voiture/paris/citroen-c3-1608526
|