MavisAJ commited on
Commit
9698931
1 Parent(s): b68ac67

Upload 2 files

Browse files
Files changed (2) hide show
  1. cap.py +72 -0
  2. requirements.txt +4 -0
cap.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import the required Libraries
2
+ import gradio as gr
3
+ import numpy as np
4
+ import pandas as pd
5
+ import os, pickle
6
+ import re
7
+
8
+ def loaded_object(filepath= r'Gradio_App_toolkit' ):
9
+ with open(filepath,'rb') as file:
10
+ loaded_object = pickle.load(file)
11
+ return loaded_object
12
+ ###### SETUP
13
+
14
+ ###### instantiating loaded objects
15
+ loaded_object = loaded_object()
16
+ ml_model = loaded_object['model']
17
+ ml_scaler = loaded_object['scaler']
18
+ print(ml_model)
19
+ print(ml_scaler)
20
+ ####loading model
21
+ inputs = ['Origin_lat','Origin_lon','Destination_lat','Destination_lon','Trip_distance','maximum_2m_air_temperature',
22
+ 'mean_2m_air_temperature','minimum_2m_air_temperature','times_encoded','cluster_id']
23
+ #Defining the predict function
24
+
25
+ def predict(*args,scaler = ml_scaler, model =ml_model):
26
+ # Creating a dataframe of inputs
27
+ input_data = pd.DataFrame([args], columns=inputs)
28
+ print(input_data)
29
+ input_data= scaler.transform(input_data)
30
+ # Modeling
31
+ #with gr.Row():
32
+ output_str = 'Hey there,Your ETA is'
33
+ dist = 'meters'
34
+ model_output = model.predict(input_data)
35
+ return(output_str,model_output,dist)
36
+ # Function to process inputs and return prediction
37
+ # Creating a dataframe of inputs
38
+ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
39
+ gr.Markdown("# YASSIR ETA PREDICTION")
40
+ gr.Markdown("""This app uses a machine learning model to predict the ETA of trips on the Yassir Hailing App.Refer to the expander at the bottom for more information on the inputs.""")
41
+
42
+ with gr.Row():
43
+ origin_lat= gr.Slider(2.807,3.381,step = 0.01,interactive=True, value=2.807, label = 'origin_lat')
44
+ origin_lon = gr.Slider(36.589,36.82,step =0.01,interactive=True, value=36.589,label = 'origin_lon')
45
+ Destination_lat =gr.Slider(2.807,3.381,step = 0.1,interactive=True, value=2.81,label ='Destination_lat')
46
+ Destination_lon =gr.Slider(36.596,36.819,step = 0.1,interactive=True, value=36.596,label ='Destination_lon')
47
+ Trip_distance = gr.Slider(1,62028,step =100,interactive=True, value= 200,label = 'Trip_distance')
48
+
49
+ with gr.Column():
50
+ maximum_2m_air_temperature =gr.Slider(288.201, 294.411, step = 0.1,interactive=True, value=288.201,label ='maximum_2m_air_temperature')
51
+ mean_2m_air_temperature =gr.Slider(285.203, 291.593,step = 0.1,interactive=True, value=285.203,label ='mean_2m_air_temperature')
52
+ minimum_2m_air_temperature = gr.Slider( 282.348, 287.693,step = 0.1,interactive=True,value=282.348, label ='minimum_2m_air_temperature')
53
+ times_encoded = gr.Dropdown([1,2,3],label="Time of the day",value= 3)
54
+ cluster_id = gr.Dropdown([1,2,3,4,5,6,7],label="Cluster ID", value=4)
55
+ with gr.Row():
56
+ btn = gr.Button("Predict").style(full_width=True)
57
+ output = gr.Textbox(label="Prediction")
58
+ # Expander for more info on columns
59
+ with gr.Accordion("Information on inputs"):
60
+ gr.Markdown("""These are information on the inputs the app takes for predicting a rides ETA.
61
+ - origin_lat: Origin in degree latitude)
62
+ - origin_lon: Origin in degree longitude
63
+ - Destination_lat: Destination latitude
64
+ - Destination_lon: Destination logitude
65
+ - Trip Distance : Distance in meters on a driving route
66
+ - Cluster ID : Select the cluster within which you started your trip
67
+ - Time of the day: What time in the day did your trip start, 1- morning(or daytime),2 - evening 3- midnight
68
+ """)
69
+ btn.click(fn = predict,inputs= [origin_lat,origin_lon, Destination_lat, Destination_lat,Trip_distance,
70
+ maximum_2m_air_temperature,mean_2m_air_temperature, minimum_2m_air_temperature,times_encoded,
71
+ cluster_id], outputs = output)
72
+ app.launch(share = True, debug =True,server_port= 6006)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pandas==1.4.4
2
+ numpy==1.21.5
3
+ seaborn==0.11.2
4
+ scikit-learn==1.1.2