-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
50 lines (34 loc) · 1.18 KB
/
api.py
File metadata and controls
50 lines (34 loc) · 1.18 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
import os
from flask import Flask, Response, request
from flask_cors import CORS
import pandas as pd
import pickle
app = Flask(__name__)
CORS(app)
training_data = pd.read_csv(os.path.join("data", "auto-mpg.csv"))
# laden des Models
file_to_open = open(os.path.join("data", "models", "regressor_mpg.pickle"), "rb")
trained_model = pickle.load(file_to_open)
file_to_open.close()
@app.route("/", methods=["GET"])
def index():
return {"hello": "world"}
@app.route("/hello_world", methods=["GET"])
def hello_world():
return "<p>Hello World!</p>"
@app.route("/training_data", methods=["GET"])
def get_training_data():
return Response(training_data.to_json(), mimetype="application/json")
@app.route("/predict", methods=["GET"])
def predict():
# Lese die Variablen aus
zylinder = request.args.get("zylinder")
ps = request.args.get("ps")
gewicht = request.args.get("gewicht")
beschleunigung = request.args.get("beschleunigung")
baujahr = request.args.get("baujahr")
# Erstellen der Vorhersage
prediction = trained_model.predict(
[[int(zylinder), int(ps), int(gewicht), int(beschleunigung), int(baujahr)]]
)
return {"result": prediction[0]}