AntOG96 commited on
Commit
e57a300
·
1 Parent(s): 20b3f03
Files changed (1) hide show
  1. src/pages/price_estimate.py +72 -13
src/pages/price_estimate.py CHANGED
@@ -1,7 +1,6 @@
1
  import requests
2
  import streamlit as st
3
 
4
-
5
  st.markdown("# Rental Price Estimation 💸")
6
 
7
  st.markdown("""
@@ -11,16 +10,76 @@ st.markdown("""
11
  """)
12
 
13
  # Creation of the form
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # Submit button for the form
16
- submitted = st.form_submit_button("Estimate")
17
-
18
- # Processing after submission
19
- if submitted:
20
- if not model or not milage or not engine_power or not fuel or not paint_color or not \
21
- type or not private_parking or not gps or not air_conditioning or not automatic or not \
22
- getaround_connect or not speed_regulator or not winter_tires:
23
- st.error("Please fill in all the fields.")
24
- else:
25
- ...
26
- st.text(f"Rental price estimate: {round(response['prediction'], 2)} $ per day.")
 
1
  import requests
2
  import streamlit as st
3
 
 
4
  st.markdown("# Rental Price Estimation 💸")
5
 
6
  st.markdown("""
 
10
  """)
11
 
12
  # Creation of the form
13
+ with st.form("rental_price_predict"):
14
+
15
+ model = st.selectbox("Model", ("Alfa Romeo", "Audi", "BMW", "Citroën", "Ferrari", "Fiat",
16
+ "Ford", "Honda", "KIA Motors", "Lamborghini", "Lexus", "Maserati",
17
+ "Mazda", "Mercedes", "Mini", "Mitsubishi", "Nissan", "Opel",
18
+ "Peugeot", "PGO", "Porsche", "Renault", "SEAT", "Subaru",
19
+ "Suzuki", "Toyota", "Volkswagen", "Yamaha"),
20
+ index=None, placeholder="Model")
21
+
22
+ milage = st.slider("Mileage", min_value=0, max_value=600000, value=100000, step=100)
23
+
24
+ engine_power = st.slider("Engine power", min_value=0, max_value=500, value=120, step=5)
25
+
26
+ fuel = st.selectbox("Fuel", list(options_energie.keys()),
27
+ index=None, placeholder="Fuel")
28
+
29
+ paint_color = st.selectbox("Paint color", list(options_couleur.keys()),
30
+ index=None, placeholder="Paint color")
31
+
32
+ car_type = st.selectbox("Car type", list(options_type.keys()),
33
+ index=None, placeholder="Car type")
34
+
35
+ private_parking = st.selectbox("Private parking", list(options_bool.keys()),
36
+ index=None, placeholder="Private parking")
37
+
38
+ gps = st.selectbox("GPS", list(options_bool.keys()),
39
+ index=None, placeholder="GPS")
40
+
41
+ air_conditioning = st.selectbox("Air conditioning", list(options_bool.keys()),
42
+ index=None, placeholder="Air conditioning")
43
+
44
+ automatic = st.selectbox("Automatic", list(options_bool.keys()),
45
+ index=None, placeholder="Automatic")
46
+
47
+ getaround_connect = st.selectbox("GetAround Connect", list(options_bool.keys()),
48
+ index=None, placeholder="GetAround Connect")
49
+
50
+ speed_regulator = st.selectbox("Speed regulator", list(options_bool.keys()),
51
+ index=None, placeholder="Speed regulator")
52
+
53
+ winter_tires = st.selectbox("Winter tires", list(options_bool.keys()),
54
+ index=None, placeholder="Winter tires")
55
+
56
+ # Submit button for the form
57
+ submitted = st.form_submit_button("Estimate")
58
+
59
+ # Processing after submission
60
+ if submitted:
61
+ if not model or not milage or not engine_power or not fuel or not paint_color or not \
62
+ car_type or not private_parking or not gps or not air_conditioning or not automatic or not \
63
+ getaround_connect or not speed_regulator or not winter_tires:
64
+ st.error("Please fill in all the fields.")
65
+ else:
66
+ payload = {
67
+ "model_key": model,
68
+ "mileage": milage,
69
+ "engine_power": engine_power,
70
+ "fuel": options_energie[fuel],
71
+ "paint_color": options_couleur[paint_color],
72
+ "car_type": options_type[car_type],
73
+ "private_parking_available": options_bool[private_parking],
74
+ "has_gps": options_bool[gps],
75
+ "has_air_conditioning": options_bool[air_conditioning],
76
+ "automatic_car": options_bool[automatic],
77
+ "has_getaround_connect": options_bool[getaround_connect],
78
+ "has_speed_regulator": options_bool[speed_regulator],
79
+ "winter_tires": options_bool[winter_tires]
80
+ }
81
+
82
+ r = requests.post("https://marjg-getaround-api.hf.space/predict", json=payload)
83
+ response = r.json()
84
 
85
+ st.text(f"Rental price estimate: {round(response['prediction'], 2)} $ per day.")