File size: 1,500 Bytes
b7b112a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# pip install flask

from flask import Flask,render_template,request
import tensorflow as tf
import pickle
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import MinMaxScaler



# If you need to inverse transform, you can use scaler.inverse_transform(scaled_data)


# loading the label encoder 
#le=pickle.load(open('label_encoder.pkl','rb'))

# loading my mlr model
model=pickle.load(open('modelrff.pkl','rb'))

#loading Scaler
scalar=pickle.load(open('scaler.pkl','rb'))

# Flask is used for creating your application
# render template is use for rendering the html page


app= Flask(__name__)  # your application


@app.route('/')  # default route 
def home():
    return render_template('home.html') # rendering if your home page.

@app.route('/pred',methods=['POST']) # prediction route
def predict1():
    '''
    For rendering results on HTML 
    '''
    
    rd = request.form["Signal_Strength"]
    ad= request.form["Latency"]
    ms = request.form["Required_Bandwidth"]
    s = request.form["type"]
    p = request.form["Allocated_Bandwidth"]
    t = np.array([[float(rd),float(ad),float(ms),float(s),float(p)] ])
    x=scalar.transform(t)
    output =model.predict(x)
    
    
    return render_template("home.html", result = "The predicted Resource_Allocation is  "+str(np.round(output[0])))
    
    
    
# running your application
if __name__ == "__main__":
    app.run()

#http://localhost:5000/ or localhost:5000