-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (31 loc) · 1.27 KB
/
main.py
File metadata and controls
43 lines (31 loc) · 1.27 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
from flask import Flask, request, jsonify
import pickle
import pandas as pd
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
def predict(input_data):
# Load the Prophet model from the pickle file
with open("prophet_model.pkl", "rb") as pickleFile:
model = pickle.load(pickleFile)
# Create a DataFrame with the date you want to predict
# The date is passed as input_data
date = input_data # Assume the date comes as a string in the input_data
# date = pd.to_datetime(date).date() # Convert it to a date
future = pd.DataFrame({"ds": [date]})
# Make predictions
predictions = model.predict(future)
# For simplicity, returning the 'yhat' value as a prediction (forecasted value)
return predictions[["ds", "yhat"]].to_dict(orient="records")[
0
] # Returning the first prediction as a dictionary
@app.route("/predict", methods=["POST"])
def predict_route():
data = request.get_json()
input_data = data["inputData"] # Expecting 'inputData' as a key with date value
# Call the predict function to get prediction
prediction = predict(input_data)
# Return the prediction as a JSON response
return jsonify({"prediction": prediction})
if __name__ == "__main__":
app.run(debug=True, port=5000)