Spaces:
Build error
Build error
File size: 1,206 Bytes
2f9956d |
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 |
import streamlit as st
import numpy as np
import pickle
import math
def haversine(pickup_longitude, pickup_latitude, dropoff_longitude, dropoff_latitude):
R = 6371.0
phi1 = math.radians(pickup_latitude)
phi2 = math.radians(dropoff_latitude)
delta_phi = math.radians(dropoff_latitude - pickup_latitude)
delta_lambda = math.radians(dropoff_longitude - pickup_longitude)
a = math.sin(delta_phi / 2.0)**2 + math.cos(phi1) * math.cos(phi2) * math.sin(delta_lambda / 2.0)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
return distance
p_lo=st.number_input("Pickup Longitude")
p_la=st.number_input("Pickup Latitude")
d_lo=st.number_input("Dropoff Longitude")
d_la=st.number_input("Dropoff Latitude")
passenger_count=st.number_input("Passenger Count")
distance=haversine(p_lo,p_la,d_lo,d_la)
file_path = 'newyorkcity_model.pkl'
with open(file_path, 'rb') as file:
model = pickle.load(file)
data=[distance,passenger_count]
if st.button("Predict"):
data=np.array(data)
if len(data.shape) == 1:
data = np.expand_dims(data, axis=0)
prediction=model.predict(data)
st.write(prediction) |