Skip to content

Commit

Permalink
Fix non-working app.
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-perseus committed Dec 1, 2023
1 parent 1bcf382 commit b5f4ad8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
from flask import Flask, jsonify, request
from deploy.predict import Predict

from deploy.single_prediction import SinglePrediction

app = Flask(__name__)
predict = Predict("deploy/model_scripted.pt")
single_prediction = SinglePrediction("deploy/model_scripted.pt", "data/preprocessing/raw_features_2024.csv")


@app.route('/')
Expand All @@ -24,7 +23,7 @@ def predict():
date = request.json['date']
print(date)

output_dicts = predict.predict_for_date(date)
output_dicts = single_prediction.predict_for_date(date)
return jsonify(output_dicts)


Expand Down
7 changes: 3 additions & 4 deletions deploy/predict.py → deploy/single_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
batch_size = 1 # Required for model input
parking_data_labels = ["P24", "P44", "P42", "P33", "P23", "P25", "P21", "P31", "P53", "P32", "P22", "P52", "P51",
"P43"] # TODO get these from metadata file
raw_features_path = "data/preprocessing/raw_features_2024.csv"


class Predict:
def __init__(self, model_path):
class SinglePrediction:
def __init__(self, model_path, raw_features_path):
self.single_prediction_features = SinglePredictionFeatures(raw_features_path)
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
self.model = torch.jit.load(model_path, map_location=self.device)
Expand Down Expand Up @@ -37,5 +36,5 @@ def predict_for_date(self, date):


if __name__ == "__main__":
predict = Predict("model_scripted.pt")
predict = SinglePrediction("model_scripted.pt", "../data/preprocessing/raw_features_2024.csv")
print(predict.predict_for_date("2023-10-09 00:00"))

0 comments on commit b5f4ad8

Please sign in to comment.