martinnnuez
commited on
Commit
•
d8dd7a3
1
Parent(s):
05fe082
Upload app y requierements
Browse files- app.py +55 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import gradio as gr
|
5 |
+
import pathlib
|
6 |
+
#plt = platform.system()
|
7 |
+
#if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
8 |
+
|
9 |
+
with open('lin_reg.bin', 'rb') as f_in:
|
10 |
+
(dv, model) = pickle.load(f_in)
|
11 |
+
|
12 |
+
def prepare_features(ride):
|
13 |
+
features = {}
|
14 |
+
features['PU_DO'] = '%s_%s' % (ride['PULocationID'], ride['DOLocationID'])
|
15 |
+
features['trip_distance'] = ride['trip_distance']
|
16 |
+
return features
|
17 |
+
|
18 |
+
def predict(features):
|
19 |
+
X = dv.transform(features)
|
20 |
+
preds = model.predict(X)
|
21 |
+
return float(preds[0])
|
22 |
+
|
23 |
+
def main(X1,X2):
|
24 |
+
"""request input, preprocess it and make prediction"""
|
25 |
+
input_data = {
|
26 |
+
"PU_DO": X1,
|
27 |
+
"trip_distance": X2
|
28 |
+
}
|
29 |
+
features = prepare_features(input_data)
|
30 |
+
pred = predict(features)
|
31 |
+
|
32 |
+
result = {
|
33 |
+
'duration': pred
|
34 |
+
}
|
35 |
+
|
36 |
+
return result
|
37 |
+
|
38 |
+
def classify_image(img):
|
39 |
+
#create input and output objects
|
40 |
+
#input
|
41 |
+
input1 = gr.inputs.Number()
|
42 |
+
input2 = gr.inputs.Number()
|
43 |
+
|
44 |
+
#output object
|
45 |
+
output = gr.outputs.Textbox()
|
46 |
+
|
47 |
+
intf = gr.Interface(title = "New York taxi duration prediction",
|
48 |
+
description = "The objective of this project is to predict the duration of a taxi trip in the city of New York.",
|
49 |
+
fn=main,
|
50 |
+
inputs=[input1,input2],
|
51 |
+
outputs=[output],
|
52 |
+
live=True,
|
53 |
+
enable_queue=True
|
54 |
+
)
|
55 |
+
intf.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
pandas==2.1.1
|
2 |
+
scikit-learn==1.3.1
|