File size: 1,719 Bytes
8753927
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
import numpy as np
import pickle
import math
from custom_data import CustomData,PredictPipeline

app = Flask(__name__)

df = pickle.load(open("df.pkl", "rb"))

@app.route("/")
def index():
    return render_template(
        "index.html",
        company=df["Company"].unique(),
        typename=df["TypeName"].unique(),
        cpu=df["CPU_brand"].unique(),
        gpu=df["Gpu_brand"].unique(),
        os=df["os"].unique()
    )

@app.route("/predict", methods=["POST"])
def predict():
    data = request.get_json()

    # Extract data
    company = data["company"]
    typename = data["typename"]
    ram = int(data["ram"])
    weight = float(data["weight"])
    screen_size = float(data["screen_size"])
    touchscreen = 1 if data["touchscreen"] == "yes" else 0
    ips = 1 if data["ips"] == "yes" else 0

    res = data["resolution"]
    x_res = int(res.split("x")[0])
    y_res = int(res.split("x")[1])
    ppi = (((x_res ** 2) + (y_res ** 2)) ** 0.5) / screen_size

    cpu = data["cpu"]
    gpu = data["gpu"]
    os = data["os"]
    hdd = int(data["hdd"])
    ssd = int(data["ssd"])

    custom_data=CustomData(company,typename,ram,weight,touchscreen,ips,ppi,cpu,gpu,os,hdd,ssd)
    custom_data_dataframe=custom_data.get_data_as_dataframe()
    predict_pileline=PredictPipeline()
    print(custom_data_dataframe)
    output=predict_pileline.predict(custom_data_dataframe)
    print(output)

    # output_n = math.floor(np.exp(output[0]))
    # print(output_n)

    return jsonify({"price": output})

if __name__ == "__main__":
    #app.run(debug=True)
    app.run(host="0.0.0.0", port=7860)