0

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

1
  • Try to follow this question and its answer. There you can find the link for a tutorial and in the post some other details about your problem. Commented Mar 23, 2023 at 7:56

1 Answer 1

0

Hello i finally fix my issues with my code. First i crate a completly new droplet and followed this tutorial

I'm folowing the code so i got the same names as in tutrial also path like this ../model/vgg_19_92%_93% casusing an error so i must change it to home/kremobil/cancelthecancer/model/vgg_19_92%_93%

here is files i changed or crated

cancelthecancer.py previously app.py:

import flask_restful
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(host='0.0.0.0')

here is predict.py:

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('/home/kremobil/cancelthecancer/model/vgg19_92%_93%')
        prediction = loaded_model.predict(img)[0][0]
        return {"result": float(prediction)}

and here is new crated wsgi.py like in tutorial:

from cancelthecancer import app

if __name__ == "__main__":
    app.run()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.