def upload_file(): finaloutput = {} if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: print('No file part') return redirect(request.url) file = request.files['file'] # if user does not select file, browser also # submit a empty part without filename if file.filename == '': print('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # tfoutput = labelimage.test(file) tfoutput = labelimage.test( os.path.join(app.config['UPLOAD_FOLDER'], filename)) finaloutput = {} finaloutput['results'] = {} finaloutput['results']['status'] = ("not diseased." in tfoutput) finaloutput['results']['confidence'] = float(tfoutput[-8:-1]) os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename)) tfoutput = "" finaloutput = json.dumps(finaloutput) # print(finaloutput) # return json.dumps(finaloutput) return finaloutput
def do_POST(self): r, info, fn, filename = self.deal_post_data() print r, info, "by: ", self.client_address f = StringIO() f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">') f.write("<html><head><meta charset=\"utf-8\"/>\n<title>Results Page</title></head>\n") f.write("<body>\n<h2>Results Page</h2>\n") f.write("<hr>\n") if r: tfoutput = labelimage.test(fn) f.write("<strong>Successful upload.</strong>") finaloutput = tfoutput + "%" f.write("<br><p>Algorithms show that the image provided is " + finaloutput +"</p>") f.write("<br><img height = 400 width = 600 src = \"" + filename + "\"></img><br><br>") else: f.write("<strong>Upload failed. \n</strong>") f.write("<a href=\"%s\">Click to return</a>" % self.headers['referer']) f.write("</a>.</small><a href=\"https://github.com/nomikxyz/retinopathy-server\"><img style=\"position: absolute; top: 0; right: 0; border: 0;\" src=\"https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67\" alt=\"Fork me on GitHub\" data-canonical-src=\"https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png\"></a></body>\n</html>\n") length = f.tell() f.seek(0) self.send_response(200) self.send_header("Content-type", "text/html") self.send_header("Content-Length", str(length)) self.end_headers() if f: self.copyfile(f, self.wfile) f.close()
def beginTensorflowAnalysis(self): tfoutput = labelimageb.test(self.image_var) labelimageb.createdialog(self, tfoutput)