HyraXuna commited on
Commit
d434262
·
verified ·
1 Parent(s): f4cf720

adding price prediction with api using

Browse files
Files changed (1) hide show
  1. app.py +70 -1
app.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  import numpy as np
4
  import plotly.express as px
5
  import plotly.graph_objects as go
 
6
 
7
 
8
  #################################################################### PAGE CONFIGURATION ####################################################################
@@ -12,7 +13,7 @@ st.set_page_config(page_title="Getaround Project Dashboard", page_icon="🚦", l
12
  #################################################################### SIDEBAR MENU ####################################################################
13
 
14
  st.sidebar.title("Navigation")
15
- page = st.sidebar.radio("Go to", ["🏠 Home/Introduction", "📊 Delays Analysis", "🎉 The End & Thank You"])
16
 
17
  e = st.sidebar.empty()
18
  e.write("")
@@ -571,6 +572,74 @@ elif page == "📊 Delays Analysis":
571
  ✨ Thanks for reading all the way through! I hope you enjoyed it and found it interesting.
572
  Go to the last page, `The End & Thank You`, for a little surprise and links to my other works‼️
573
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
 
575
  #################################################################### END & THANK YOU PAGE ####################################################################
576
 
 
3
  import numpy as np
4
  import plotly.express as px
5
  import plotly.graph_objects as go
6
+ import requests
7
 
8
 
9
  #################################################################### PAGE CONFIGURATION ####################################################################
 
13
  #################################################################### SIDEBAR MENU ####################################################################
14
 
15
  st.sidebar.title("Navigation")
16
+ page = st.sidebar.radio("Go to", ["🏠 Home/Introduction", "📊 Delays Analysis", "💸 Price Prediction", "🎉 The End & Thank You"])
17
 
18
  e = st.sidebar.empty()
19
  e.write("")
 
572
  ✨ Thanks for reading all the way through! I hope you enjoyed it and found it interesting.
573
  Go to the last page, `The End & Thank You`, for a little surprise and links to my other works‼️
574
  """)
575
+ #################################################################### Price prediction ####################################################################
576
+
577
+ elif page == "💸 Price Prediction":
578
+ st.title("Price Prediction for a Rental 💸💶")
579
+ st.markdown("""
580
+ Here, you can choose the parameters of a car and with a connection to my API, you can have a day price prediction of the car.
581
+
582
+ 🟠 **What you'll find in this page**:
583
+ * 🏎️ Object to select your car's characteristics?
584
+ * 💸 A price prediction for one rental day.
585
+ """)
586
+
587
+ st.write("Select the car parameters below and get an estimated rental price!")
588
+
589
+ # Define API URL
590
+ api_url = "https://hyraxuna-api-getaround.hf.space/predict"
591
+
592
+ # Define input fields for car parameters
593
+ car_model = st.selectbox("Car Brand:", ['Citroën','Peugeot','PGO','Renault','Audi','BMW','Mercedes','Opel','Volkswagen','Ferrari','Mitsubishi','Nissan','SEAT','Subaru','Toyota','other'])
594
+ mileage = st.slider("Mileage (km):", 0, 300000, 50000, step=1000)
595
+ engine_power = st.slider("Engine Power (HP):", 50, 500, 150, step=10)
596
+ fuel = st.selectbox("Fuel Type:", ['diesel','petrol','other'])
597
+ paint_color = st.selectbox("Paint Color:", ['black','grey','white','red','silver','blue','beige','brown','other'])
598
+ car_type = st.selectbox("Car Type:", ['convertible','coupe','estate','hatchback','sedan','subcompact','suv','van'])
599
+
600
+ # Boolean Features
601
+ private_parking_available = st.checkbox("Private Parking Available")
602
+ has_gps = st.checkbox("GPS Included")
603
+ has_air_conditioning = st.checkbox("Air Conditioning")
604
+ automatic_car = st.checkbox("Automatic Transmission")
605
+ has_getaround_connect = st.checkbox("Getaround Connect Available")
606
+ has_speed_regulator = st.checkbox("Speed Regulator Installed")
607
+ winter_tires = st.checkbox("Winter Tires Installed")
608
+
609
+ # Button to Predict
610
+ if st.button("🔍 Predict Rental Price"):
611
+ st.subheader("💶 Prediction Results")
612
+
613
+ # Prepare input data as JSON
614
+ input_data = {
615
+ "model_key": car_model,
616
+ "mileage": mileage,
617
+ "engine_power": engine_power,
618
+ "fuel": fuel,
619
+ "paint_color": paint_color,
620
+ "car_type": car_type,
621
+ "private_parking_available": private_parking_available,
622
+ "has_gps": has_gps,
623
+ "has_air_conditioning": has_air_conditioning,
624
+ "automatic_car": automatic_car,
625
+ "has_getaround_connect": has_getaround_connect,
626
+ "has_speed_regulator": has_speed_regulator,
627
+ "winter_tires": winter_tires
628
+ }
629
+
630
+ try:
631
+ # API Request
632
+ response = requests.post(api_url, json=input_data)
633
+ result = response.json()
634
+
635
+ if response.status_code == 200:
636
+ predicted_price = result.get("predicted_price", "Error")
637
+ st.success(f"💰 Estimated Rental Price: **{predicted_price} € per day**")
638
+ else:
639
+ st.error("⚠️ Error fetching prediction. Please check API or try again.")
640
+
641
+ except Exception as e:
642
+ st.error(f"⚠️ API Request Failed: {e}")
643
 
644
  #################################################################### END & THANK YOU PAGE ####################################################################
645