I am using google vision api to convert uploaded image into text and displaying it using flask. the website is giving 504 error loadbalancer. it is working in console but showing error on the webapp. please tell me how to fix it
I am using google vision api to convert uploaded image into text and displaying it using flask. the website is giving 504 error loadbalancer. it is working in console but showing error on the webapp. please tell me how to fix it
.
app = Flask(__name__)
photos = UploadSet('photos', IMAGES)
app.config['UPLOADED_PHOTOS_DEST']="mysite"
configure_uploads(app, photos)
@app.route('/index', methods=['GET', 'POST'])
def upload():
if request.method == 'POST' and 'photo' in request.files:
filename =photos.save(request.files['photo'])
filename="mysite/"+filename
vision_client = vision.Client()
with io.open(filename, 'rb') as image_file:
content = image_file.read()
image = vision_client.image(
content=content, )
text=image.detect_full_text().text
return render_template('x.html',t="text")
return render_template('index.html')
the site keeps on loading for 3-4 minutes and then shows error 504 load balancing. arjunfzk.pythonanywhere.com/index after uploading file keeps on loading and then shows error.
is it possible that that image.detect_full_text()
function is taking a very long time to complete? try removing it and replacing it with a dummy value to check. then, if it is, try moving it out to an async worker: https://help.pythonanywhere.com/pages/AsyncInWebApps/
it worked when i replaced it with some dummy value,when i ran image.detect_full_text() it takes a minute at most. is it possible that my app is not able to communicate to the web to access the api,if not how can i set up Asyncinwebapps
anything hosted on *.google.com will be accessible for free users. my guess is it's just taking too long. you can confirm by looking for the word "harakiri" in your server log (linked from the web tab)
if you see that, it's definitely timing out, and my best advice is to try an async task queue as suggested in that link.