-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
109 lines (97 loc) · 3.39 KB
/
app.py
File metadata and controls
109 lines (97 loc) · 3.39 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import numpy as np
import pickle
import pandas as pd
from flasgger import Swagger
import streamlit as st
from flask import Flask,request
app=Flask(__name__)
Swagger(app)
model=pickle.load(open(f'model.pkl','rb+'))
@app.route('/')
def welcome():
return "Welcome All"
@app.route('/predict',methods=["GET"])
def predict():
"""Let's Predict the flight price prediction.
---
parameters:
- name: Name of Airlines
in: query
enum: [" ","Air India","Go-Air","Indigo","Jet Airways","Jet Airways Business","Multi Carriers","Multi Carriers Premium Economy","Spicejet","Trujet","Vistara","Vistara Premium Economy"]
description: Select the airlines for which you want to predict the price
required: true
type: string
- name: Source
in: query
enum: [" ","Bangalore","Chennai","Delhi","Kolkata","Mumbai"]
description: Select the city where your journey starts
required: true
type: string
- name: Destination
in: query
enum: [" ","Bangalore","Cochin","Hyderabad","Delhi","Kolkata","New Delhi"]
description: Select he destination city you wanted to reach
required: true
type: string
- name: Date of Journey
in: query
type: string
description: Format is DD/MM/YYYY
required: true
- name: Arrival Time
in: query
type: string
description: Format is HH:MM
required: true
- name: Departure Time
in: query
type: string
description: Format is HH:MM
required: true
- name: Total Duration
in: query
type: number
description: Format is in minutes
required: true
- name: Total No of Stops
in: query
enum: ["Non-Stop","1-Stop","2-Stop","3-Stop","4-Stop"]
description: Select No of Stops
required: true
type: string
responses:
200:
description: The Predicted Flight Price
"""
airlines={"Air India":0,"Go-Air":1,"Indigo":2,"Jet Airways":3,"Jet Airways Business":4,"Multi Carriers":5,"Multi Carriers Premium Economy":6,"Spicejet":7,"Trujet":8,"Vistara":9,"Vistara Premium Economy":10}
source={"Bangalore":0,"Chennai":1,"Delhi":2,"Kolkata":3,"Mumbai":4}
destination={"Bangalore":0,"Cochin":1,"Hyderabad":2,"Delhi":3,"Kolkata":4,"New Delhi":5}
stops={"Non-Stop":0,"1-Stop":1,"2-Stop":2,"3-Stop":3,"4-Stop":4}
features=np.zeros(30)
airline=request.args.get('Name of Airlines')
src=request.args.get('Source')
dest=request.args.get('Destination')
dtofjrny=request.args.get('Date of Journey')
artime=request.args.get('Arrival Time')
deptime=request.args.get('Departure Time')
total=request.args.get('Total Duration')
totalstops=request.args.get('Total No of Stops')
features[0]=total
features[1]=stops[totalstops]
dtofjrny=dtofjrny.split('/')
features[2]=int(dtofjrny[1])
features[3]=int(dtofjrny[0])
artime=artime.split(':')
deptime=deptime.split(':')
features[4]=int(deptime[0])
features[5]=int(deptime[1])
features[6]=int(artime[0])
features[7]=int(artime[1])
features[8+airlines[airline]]=1
features[19+source[src]]=1
features[24+destination[dest]]=1
pred=model.predict([features])
prediction=pred[0]
return str(prediction)
if __name__ == "__main__":
app.run(debug=False)