-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (59 loc) · 2.37 KB
/
app.py
1
2
3
4
5
6
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
import streamlit as st
import requests
from datetime import datetime
'''
# TaxiFareModel front
'''
st.markdown('''
Remember that there are several ways to output content into your web page...
Either as with the title by just creating a string (or an f-string). Or as with this paragraph using the `st.` functions
''')
'''
## Here we would like to add some controllers in order to ask the user to select the parameters of the ride
1. Let's ask for:
- date and time
- pickup longitude
- pickup latitude
- dropoff longitude
- dropoff latitude
- passenger count
'''
pickup_date = st.date_input('Pickup Date',value =None , disabled=False)
pickup_time = st.time_input('Pickup Time',value =None , disabled=False)
pickup_longitude = st.number_input('Select a pickup longitude')
pickup_latitude= st.number_input('Select a pickup latitude')
dropoff_longitude = st.number_input('Select a dropoff longitude')
dropoff_latitude= st.number_input('Select a dropoff latitude')
passenger= st.number_input('Select the number of passengers')
# st.write('The current date & time is', pickup_datetime)
'''
## Once we have these, let's call our API in order to retrieve a prediction
See ? No need to load a `model.joblib` file in this app, we do not even need to know anything about Data Science in order to retrieve a prediction...
🤔 How could we call our API ? Off course... The `requests` package 💡
'''
url = 'https://taxifare.lewagon.ai/predict'
if url == 'https://taxifare.lewagon.ai/predict':
st.markdown('Maybe you want to use your own API for the prediction, not the one provided by Le Wagon...')
'''
2. Let's build a dictionary containing the parameters for our API...
3. Let's call our API using the `requests` package...
4. Let's retrieve the prediction from the **JSON** returned by the API...
## Finally, we can display the prediction to the user
'''
passenger = int(passenger)
pickup_datetime = f'{pickup_date} {pickup_time}'
data = {
# "key": "2021-07-06 17:18:00.000000119",
"pickup_datetime": f'{pickup_date} {pickup_time}',
"pickup_longitude": pickup_longitude,
"pickup_latitude": pickup_latitude,
"dropoff_longitude": dropoff_longitude,
"dropoff_latitude": dropoff_latitude,
"passenger_count": passenger
}
# pass_type = type(f'{pickup_date} {pickup_time}')
# pass_type
# pickup_datetime
r = requests.get(url, params=data)
resp = r.json()
resp