├── Flask.pdf
├── src
├── Flask.pdf
├── request.py
├── app.py
├── model.py
├── index.html
└── style.css
├── models
└── model.pkl
├── LICENSE
├── input
└── 50_Startup.csv
└── README.md
/Flask.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chiragsamal/Flask-Tutorial/HEAD/Flask.pdf
--------------------------------------------------------------------------------
/src/Flask.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chiragsamal/Flask-Tutorial/HEAD/src/Flask.pdf
--------------------------------------------------------------------------------
/models/model.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chiragsamal/Flask-Tutorial/HEAD/models/model.pkl
--------------------------------------------------------------------------------
/src/request.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | url = 'http://localhost:5000/predict_api'
4 | r = requests.post(url,json={'experience':2, 'test_score':9, 'interview_score':6})
5 |
6 | print(r.json())
--------------------------------------------------------------------------------
/src/app.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from flask import Flask, request, jsonify, render_template
3 | import pickle
4 |
5 | app = Flask(__name__)
6 | model = pickle.load(open('model.pkl', 'rb'))
7 |
8 | @app.route('/')
9 | def home():
10 | return render_template('index.html')
11 |
12 | @app.route('/predict',methods=['POST'])
13 | def predict():
14 | '''
15 | For rendering results on HTML GUI
16 | '''
17 | int_features = [int(x) for x in request.form.values()]
18 | final_features = [np.array(int_features)]
19 | prediction = model.predict(final_features)
20 |
21 | output = round(prediction[0], 2)
22 |
23 | return render_template('index.html', prediction_text='Employee Salary should be $ {}'.format(output))
24 |
25 | @app.route('/predict_api',methods=['POST'])
26 | def predict_api():
27 | '''
28 | For direct API calls trought request
29 | '''
30 | data = request.get_json(force=True)
31 | prediction = model.predict([np.array(list(data.values()))])
32 |
33 | output = prediction[0]
34 | return jsonify(output)
35 |
36 | if __name__ == "__main__":
37 | app.run(debug=True)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Chirag Samal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/model.py:
--------------------------------------------------------------------------------
1 | # Importing the libraries
2 | import numpy as np
3 | import matplotlib.pyplot as plt
4 | import pandas as pd
5 | import pickle
6 |
7 | dataset = pd.read_csv('hiring.csv')
8 |
9 | dataset['experience'].fillna(0, inplace=True)
10 |
11 | dataset['test_score'].fillna(dataset['test_score'].mean(), inplace=True)
12 |
13 | X = dataset.iloc[:, :3]
14 |
15 | #Converting words to integer values
16 | def convert_to_int(word):
17 | word_dict = {'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8,
18 | 'nine':9, 'ten':10, 'eleven':11, 'twelve':12, 'zero':0, 0: 0}
19 | return word_dict[word]
20 |
21 | X['experience'] = X['experience'].apply(lambda x : convert_to_int(x))
22 |
23 | y = dataset.iloc[:, -1]
24 |
25 | #Splitting Training and Test Set
26 | #Since we have a very small dataset, we will train our model with all availabe data.
27 |
28 | from sklearn.linear_model import LinearRegression
29 | regressor = LinearRegression()
30 |
31 | #Fitting model with trainig data
32 | regressor.fit(X, y)
33 |
34 | # Saving model to disk
35 | pickle.dump(regressor, open('model.pkl','wb'))
36 |
37 | # Loading model to compare the results
38 | model = pickle.load(open('model.pkl','rb'))
39 | print(model.predict([[2, 9, 6]]))
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |