Hello I'm trying to run my flask app on ubuntu server (digital ocean droplet) but I encounter some weird error.
The error message says that the path of file is incorrect but I have changed this file and now it doesn't contains any paths so I'd know why I see this error.
Here is the error message:
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/flask/views.py", line 107, in view
return current_app.ensure_sync(self.dispatch_request)(**kwargs)
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
resp = meth(*args, **kwargs)
File "/var/www/html/cancel-the-cancer/Resources/predict.py", line 10, in post
img = img.resize((256, 256))
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/werkzeug/datastructures.py", line 3002, in save
dst = open(dst, "wb")
FileNotFoundError: [Errno 2] No such file or directory: './images/ISIC_0029612.jpg.jpg'
Here is predic.py file:
import numpy as np
from flask_restful import Resource, request
import tensorflow as tf
from PIL import Image
class Predict(Resource):
def post(self):
file = request.files['image']
img = Image.open(file.stream)
img = img.resize((256, 256))
img = np.array(img)
img = img / 255.0
img = np.expand_dims(img, axis=0)
loaded_model = tf.keras.models.load_model('../model/vgg19_92%_93%')
prediction = loaded_model.predict(img)[0][0]
return {"result": float(prediction)}
Here is app.py file:
import flask_restful
from flask_cors import CORS
from flask_cors import CORS
from flask import Flask
from flask_restful import Api
from Resources.predict import Predict
app = Flask(__name__)
app.secret_key = 'zwolnienizteorii44893'
api = Api(app)
cors = CORS(app)
api.add_resource(Predict, '/predict')
if __name__ == '__main__':
app.run(port=5000, debug=True)
I have also try the same application on my personal computer with windows 11 and on win it works well and returns predict but on ubuntu as api response i receive internal server error.
im trying
sudo systemctl restart uwsgi
sudo systemctl restart nginx
sudo systemctl reload uwsgi
sudo systemctl reload nginx