def index(): form = URLForm() timg = Image(False, "", "", "") botError = BotError(False, "") if form.validate_on_submit(): url = form.query.data try: # resize image to 32x32 pixel image procImage = allcnn_predict.processImage(url) # transform to 32,32,3 matrix, feed to model category, prob = allcnn_predict.predictImage(procImage) timg = Image(True, url, category, prob) timg.toString() except ValueError as e: print(e) botError = BotError(True, e) except urllib.error.HTTPError as e: print(e.msg) botError = BotError(True, e.msg) return render_template("index.html", title='VisionBot', form=form, botError=botError, image=timg) return render_template("index.html", title='VisionBot', form=form, botError=botError, image=timg)
def move(url): page = wiki.get_or_404(url) form = URLForm(obj=page) if form.validate_on_submit(): newurl = form.url.data wiki.move(url, newurl) return redirect(url_for('.display', url=newurl)) return render_template('move.html', form=form, page=page)
def flow(): """Route vers le lecteur d'URL pour flux rss/atom""" user_id = current_user.get_id() form = URLForm() if form.validate_on_submit(): flow = Flow(url=form.url.data, user=user_id) flow.save() return render_template("flow.html", form=form)
def getURL(): form = URLForm() if form.validate_on_submit(): # [...] print "input URL: %s" % form.url.data return redirect(url_for('getBS_img', imageurl=form.url.data)) return render_template('enterurl.html', form=form)
def getBS_img_multi(): import base64 defaultURL = chooseDefaultURLfromList() imageurl = request.args.get('imageurl', default=defaultURL) #remove quotes in url if any imageurl = imageurl.strip('"').strip('\'') if not imageurl.startswith("http"): imageurl = "http:\\" + imageurl #number of clustering versions to show number_iter = request.args.get('iter', default=5, type=int) #SHOW_SIMPLER_IMAGES config from url SHOW_SIMPLER_IMAGES = request.args.get('show_simpler_images', default=False, type=bool) print "SHOW_SIMPLER_IMAGES --", str(SHOW_SIMPLER_IMAGES) #get data from image comment (comment, colors, drawn colors) #imageresponse = imageapp.commentOnImageFullMode(imageurl,number_iter,SHOW_SIMPLER_IMAGES) #REDIS enqueue blocking function #imageresponse = imageapp.commentOnImage(imageurl) job = q.enqueue(imageapp.commentOnImageFullMode, imageurl, number_iter, SHOW_SIMPLER_IMAGES) # TODO: how long to wait? while not job.result: imageresponse = '' imageresponse = job.result imagecomment = imageresponse["comment"] maincolorstringslist = imageresponse["maincolorstringslist"] silhouettescores = imageresponse["silhouettescores"] colorboxes = imageresponse["colorboxes"] simplerimages = imageresponse["simplerimages"] #print "len(simplerimages):", len(simplerimages) #print silhouettescores #print len(silhouettescores) form = URLForm() if form.validate_on_submit(): # [...] print "input URL: %s" % form.url.data return redirect(url_for('getBS_img_multi', imageurl=form.url.data)) return render_template("getbs_img_multi.html", imagecomment=imagecomment, imageurl=imageurl, maincolorstringslist=maincolorstringslist, silhouettescores=silhouettescores, colorboxes=colorboxes, simplerimages=simplerimages, SHOW_SIMPLER_IMAGES=SHOW_SIMPLER_IMAGES, form=form)
def index(): form = URLForm() # over here, form submission if request.method == "POST": if form.validate_on_submit(): print("Got form! URL is:", form.url.data) reviews, data = backend.scrape(form.url.data) sys.stdout.flush() if (reviews is None): print("Something went wrong.") sys.stdout.flush() flash( "Something went wrong, either invalid URL or internal server error." ) return render_template("index.html", form=form) num_fake, num_real = 0, 0 num_fake_stars, num_real_stars = 0, 0 for review in reviews: predict, conf = backend.classify(review["rating"], review["product_category"], review["verified"], review["review_text"]) num_fake += 1 if predict == "FAKE" else 0 num_real += 0 if predict == "FAKE" else 1 num_fake_stars += review["rating"] if predict == "FAKE" else 0 num_real_stars += 0 if predict == "FAKE" else review["rating"] product_data = {} product_data["percentage_fake"] = int( (num_fake / (num_real + num_fake)) * 100) product_data["raw_rating"] = round( (num_fake_stars + num_real_stars) / (num_fake + num_real), 2) product_data["adjusted_rating"] = round( (num_real_stars) / (num_real), 2) product_data["title"] = data["title"] product_data["price"] = data["price"] product_data["image_url"] = data["image"] product_data["url"] = form.url.data # return here index.html, but with the product info return render_template("index.html", form=form, product_data=product_data) else: flash("Invalid URL") # over here, form request return render_template("index.html", form=form)
def index(): """ Главная страница """ form = URLForm() if form.validate_on_submit(): url = db.session.query(ShortURL).filter_by(full_url=form.url_string.data).first() if url: return redirect(url_for('short_page', short_url=url.short_url)) else: new_url = ShortURL(full_url=form.url_string.data, short_url=random_url()) db.session.add(new_url) db.session.commit() return redirect(url_for('short_page', short_url=new_url.short_url)) return render_template('index.html', form=form)
def add(): urlform = URLForm(request.form) pform = PreviewForm(request.form) sourceform = SourceForm(request.form) curr=True print sourceform.validate() if urlform.validate_on_submit() and not pform.validate_on_submit(): track = get_track_info(urlform.url.data) pform.songname.data = track.title pform.artist.data = track.user['username'] pform.label.data = track.label_name if pform.label.data is None: pform.label.data = '' pform.year.data = track.release_year if pform.year.data is None: pform.year.data = '' curr=False elif sourceform.validate_on_submit(): add_source(sourceform.source.data, sourceform.genre.data) return redirect(url_for("index")) elif pform.validate_on_submit(): add_track(pform.url.data, current_user.id, "user", pform.songname.data, pform.artist.data, pform.genre.data, pform.label.data, pform.year.data) return render_template("add.html", urlform=urlform, previewform=pform, sourceform=sourceform, curr=curr)
def getBS_img(): defaultURL = chooseDefaultURLfromList() imageurl = request.args.get('imageurl', default=defaultURL) #remove quotes in url if any imageurl = imageurl.strip('"').strip('\'') if not imageurl.startswith("http"): imageurl = "http:\\" + imageurl #number of clusters to use --TODO: do something with it number_clusters = request.args.get('clusters', default=5) form = URLForm() if form.validate_on_submit(): # [...] print "input URL: %s" % form.url.data try: return redirect(url_for('getBS_img', imageurl=form.url.data)) except Exception as err: print "error in form bit -- %s" % str(err) ##CALL TEMPLATE WITH JUST AVAILABLE DATA## ##The page then call /startimageanalysis to start the job and /result to update## return render_template('getbs_img2.html', imageurl=imageurl, form=form) '''
def create(): form = URLForm() if form.validate_on_submit(): return redirect(url_for('edit', url=form.clean_url(form.url.data))) return render_template('create.html', form=form)