Skip to content

Commit

Permalink
Pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
atrakic committed Sep 14, 2023
1 parent 26b4235 commit 57aa45e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- 'ml-model/**'
- 'frontend/**'
- 'test-client/**'
jobs:
build:
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[MASTER]
disable=
C0301, # Line too long
C0114, # missing-module-docstring
C0116,
C0115,
E0401, # Unable to import
16 changes: 9 additions & 7 deletions frontend/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from flask import Flask, jsonify, render_template, request

model_file = os.getenv("MODEL_FILE")
model = pickle.load(open(model_file, "rb"))

with open(model_file, "rb") as f:
model = pickle.load(f)

app = Flask(__name__)

Expand All @@ -17,12 +19,12 @@ def index():

@app.route("/predict", methods=["POST"])
def predict():
# rooms = int(request.form["rooms"])
# distance = int(request.form["distance"])
int_inputs = [int(x) for x in request.form.values()]
arr = [np.array(int_inputs)]
prediction = model.predict(arr)
# prediction = model.predict([[rooms, distance]])
rooms = int(request.form["rooms"])
distance = int(request.form["distance"])
prediction = model.predict([[rooms, distance]])
# int_inputs = [int(x) for x in request.form.values()]
# arr = [np.array(int_inputs)]
# prediction = model.predict(arr)
output = round(prediction[0], 2)
return render_template(
"index.html",
Expand Down
5 changes: 3 additions & 2 deletions ml-model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
print(f"Model intercept : {lm.intercept_}")
print(f"Model predict : {lm.predict([[15, 61]])}") # format of input

pickle.dump(lm, open(model_file, "wb")) # serialize and save the model to the file
print("Created model file : ", model_file)
with open(model_file, "wb") as f:
pickle.dump(lm, f)
print("Created model file : ", model_file)
34 changes: 19 additions & 15 deletions test-client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import urllib.parse
import urllib.request
from pprint import pprint
from urllib.error import HTTPError, URLError

url = os.getenv("API_URL")

values = {"rooms": 2, "distance": 20}
VALUES = {"rooms": 2, "distance": 20}

data = urllib.parse.urlencode(values)
data = data.encode("ascii") # data should be bytes
data = json.dumps(values).encode("utf-8")
DATA = urllib.parse.urlencode(VALUES)
DATA = DATA.encode("ascii") # should be bytes
data = json.dumps(VALUES).encode("utf-8")

try:
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
req = urllib.request.Request(url, data, headers)
with urllib.request.urlopen(req) as f:
res = f.read()
pprint(res.decode())
except Exception as e:
pprint(e)
if __name__ == "__main__":
try:
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
req = urllib.request.Request(url, data, headers)
with urllib.request.urlopen(req) as f:
res = f.read()
pprint(res.decode())
except HTTPError as e:
print("Error code: ", e.code)
except URLError as e:
pprint(e)

0 comments on commit 57aa45e

Please sign in to comment.