0

I am trying to create a face recognition API where I have a function face_rec(image) given an image file will return the names of people in the image as string.

Now I want my flask API so that I can call

0.0.0.0:5000/face_rec?file=https://www.rd.com/wp-content/uploads/2018/03/rdj.jpg

and it will return the name (in this case Robert Downey JR)

which I have no problem with face_rec but I cannot get the file input as a URL argument to work

@app.route('/face_rec', methods=['POST', 'GET'])
def face_recognition():
    file = request.args.get('file')
    print(file)
    name = face_rec(file)
    resp_data = {'name': name}
    return json.dumps(resp_data)
user8606643
  • 13
  • 1
  • 7
  • Possible duplicate of https://stackoverflow.com/questions/30743105/flask-how-to-get-query-string-parameters-into-the-route-parameters – dmitryro Apr 30 '20 at 14:46
  • https://stackoverflow.com/questions/24892035/how-can-i-get-the-named-parameters-from-a-url-using-flask – dmitryro Apr 30 '20 at 14:47
  • @dmitryro the links you have sent are all about string parameters or other types (for example username password) what I want is a URL to the image file that can be used for processing further – user8606643 Apr 30 '20 at 15:00
  • Why can't you follow REST and pass the value with `/` after the endpoint name - any particular reason you have to pass it this way? You can print your `request.args` dictionary and see what's there. – dmitryro Apr 30 '20 at 15:04
  • Oh do you mean like this? 0.0.0.0:5000/face_rec/https://www.rd.com/wp-content/uploads/2018/03/rdj.jpg If so then this produces an error because it's like another URL in the localhost URL – user8606643 Apr 30 '20 at 15:08
  • You then can pass your parameter as `def face_recognition(file):` and change your route decorator to be `@app.route('/face_rec/')`, but anyhow you can output the dictionary you get from request and see what's there. – dmitryro Apr 30 '20 at 15:12
  • @dmitryro yes I just tried that and all I get is Not Found ```The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.``` – user8606643 Apr 30 '20 at 15:21
  • You can specify `` so you get it as string. Also make sure you're decoding your url properly. – dmitryro Apr 30 '20 at 16:53

0 Answers0