Hello!! I am trying to load a pickle file into my flask app (python) because I am trying to make predictions with my model. When executing this code local it woks perfect and loads the file. When deploying it to render it does not load the file: it returns “Error”.
The pickle file is in GitHub, the path is correct, because it doesn’t return a FileNotFoundError. I am not really sure if the problem is that render cannot load a pickle file? When loading a txt the same way it works.
I hope someone could help me, thank you!!
import pandas as pd
import numpy as np
from flask import Flask, request, jsonify, abort, make_response
from flask_cors import CORS
from dotenv import load_dotenv
import os
import pickle
from datetime import date
app = Flask(name)
app.config[‘DEBUG’] = True
CORS(app, support_credentials=True)
def load_object(filename):
with open(filename ,‘rb’) as f:
loaded = pickle.load(f)
return loaded
@app.route(‘/retrain’, methods=[‘GET’])
def prueba():
try:
model=load_object(“/opt/render/project/src/api/JP_12_06_VotingRegressor.pickle”)
return “Done”
except FileNotFoundError:
return “File not found”
except:
return “Error”
if name == ‘main’:
app.run(host=‘0.0.0.0’, port=5000)