gdleds commited on
Commit
8ec7c50
·
1 Parent(s): 19950c1

grosse modif

Browse files
Files changed (1) hide show
  1. app.py +40 -59
app.py CHANGED
@@ -354,67 +354,48 @@ with tab2:
354
  Présence de GPS = + valeur ajoutée """)
355
 
356
  with tab3:
357
-
358
- st.header("🔮 Prédiction du prix de location via l’API")
359
-
360
- # URL de ton API Hugging Face
361
- API_URL = "https://gdleds-api-get.hf.space/predict"
362
-
363
- # --- Formulaire ---
364
- with st.form("predict_form"):
365
- st.subheader("Remplissez les caractéristiques du véhicule")
366
-
367
- # Sélection de la marque
368
- model_key = st.selectbox(
369
- "Marque",
370
- ["Audi", "BMW", "Citroën", "Peugeot", "Renault", "Mercedes", "Volkswagen", "Ford", "Opel"]
371
- )
372
-
373
- mileage = st.slider("Kilométrage", 0, 300000, 50000, step=5000)
374
- engine_power = st.slider("Puissance moteur (CV)", 50, 300, 110, step=5)
375
-
376
- fuel = st.selectbox("Carburant", ["diesel", "petrol", "hybrid_petrol", "electro"])
377
- paint_color = st.selectbox("Couleur", ["black", "grey", "white", "red", "silver", "blue", "orange", "beige", "brown", "green"])
378
- car_type = st.selectbox("Type de voiture", ["convertible", "coupe", "estate", "hatchback", "sedan", "subcompact", "suv", "van"])
379
-
380
- st.markdown("**Options (True = Oui, False = Non)**")
381
- private_parking_available = st.checkbox("Parking privé disponible")
382
- has_gps = st.checkbox("GPS")
383
- has_air_conditioning = st.checkbox("Climatisation")
384
- automatic_car = st.checkbox("Boîte automatique")
385
- has_getaround_connect = st.checkbox("Getaround Connect")
386
- has_speed_regulator = st.checkbox("Régulateur de vitesse")
387
- winter_tires = st.checkbox("Pneus hiver")
388
-
389
- submitted = st.form_submit_button("🚀 Prédire le prix")
390
-
391
- # --- Envoi à l’API ---
392
- if submitted:
393
- data = {
394
- "model_key": model_key,
395
- "mileage": mileage,
396
- "engine_power": engine_power,
397
- "fuel": fuel,
398
- "paint_color": paint_color,
399
- "car_type": car_type,
400
- "private_parking_available": private_parking_available,
401
- "has_gps": has_gps,
402
- "has_air_conditioning": has_air_conditioning,
403
- "automatic_car": automatic_car,
404
- "has_getaround_connect": has_getaround_connect,
405
- "has_speed_regulator": has_speed_regulator,
406
- "winter_tires": winter_tires
407
- }
408
-
409
  try:
410
- response = requests.post(API_URL, json=data)
411
-
412
  if response.status_code == 200:
413
- price = response.json()["rental_price"]
414
- st.success(f"💰 Prix prédit : **{price} $/jour**")
415
  else:
416
  st.error(f"Erreur API ({response.status_code}) : {response.text}")
417
-
418
  except Exception as e:
419
- st.error(f" Impossible de joindre lAPI : {e}")
420
-
 
354
  Présence de GPS = + valeur ajoutée """)
355
 
356
  with tab3:
357
+ st.header("🔧 Prédiction API")
358
+
359
+ # Sélection des valeurs
360
+ model_key = st.selectbox("Marque", ["Audi", "BMW", "Peugeot", "Renault", "Citroën"])
361
+ mileage = st.number_input("Kilométrage", min_value=0, max_value=300000, value=50000, step=1000)
362
+ engine_power = st.number_input("Puissance moteur (ch)", min_value=50, max_value=300, value=110)
363
+ fuel = st.selectbox("Carburant", ["diesel", "petrol", "hybrid_petrol", "electro"])
364
+ paint_color = st.selectbox("Couleur", ["black", "grey", "white", "red", "silver", "blue", "orange", "beige", "brown", "green"])
365
+ car_type = st.selectbox("Type de voiture", ["estate", "hatchback", "sedan", "suv", "convertible", "coupe", "van"])
366
+
367
+ private_parking_available = st.checkbox("Parking privé disponible")
368
+ has_gps = st.checkbox("GPS")
369
+ has_air_conditioning = st.checkbox("Climatisation")
370
+ automatic_car = st.checkbox("Automatique")
371
+ has_getaround_connect = st.checkbox("Getaround Connect")
372
+ has_speed_regulator = st.checkbox("Régulateur de vitesse")
373
+ winter_tires = st.checkbox("Pneus hiver")
374
+
375
+ # Construire le JSON attendu
376
+ payload = {
377
+ "model_key": model_key,
378
+ "mileage": mileage,
379
+ "engine_power": engine_power,
380
+ "fuel": fuel,
381
+ "paint_color": paint_color,
382
+ "car_type": car_type,
383
+ "private_parking_available": private_parking_available,
384
+ "has_gps": has_gps,
385
+ "has_air_conditioning": has_air_conditioning,
386
+ "automatic_car": automatic_car,
387
+ "has_getaround_connect": has_getaround_connect,
388
+ "has_speed_regulator": has_speed_regulator,
389
+ "winter_tires": winter_tires
390
+ }
391
+
392
+ if st.button("🔮 Prédire le prix"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  try:
394
+ response = requests.post("https://gdleds-api-get.hf.space/predict", json=payload)
 
395
  if response.status_code == 200:
396
+ result = response.json()
397
+ st.success(f"💰 Prix estimé : {result['rental_price']} $/jour")
398
  else:
399
  st.error(f"Erreur API ({response.status_code}) : {response.text}")
 
400
  except Exception as e:
401
+ st.error(f"⚠️ Impossible d'appeler l'API : {e}")