Ejemplo n.º 1
0
def tag_condition():
	tag_select_form = TagSelectForm()
	if tag_select_form.validate_on_submit():
		hair_color = tag_select_form.hair_color_type.data
		eye_color = tag_select_form.eye_color_type.data
		illust_names = Recommender.choose_illusts_from_tag(GET_IMG_NUM, hair_color, eye_color)
		if len(illust_names) < GET_IMG_NUM:
			additional_illust_names = Recommender.choose_illusts_from_tag(GET_IMG_NUM - len(illust_names), hair_color, None)
			illust_names += additional_illust_names
		illust_paths = [os.path.join('./static/', illust_name) for illust_name in illust_names]

		if len(illust_paths) == 0:
			return render_template('no_illust.html')
			
		Recommender.stamp_used_img(illust_names)
		return render_template('show_illust.html', illust_paths=illust_paths)

	else:
		return render_template('tag_condition.html', form=tag_select_form)
Ejemplo n.º 2
0
def illust_condition():
	upload_form = IllustUploadForm()
	if upload_form.validate_on_submit():
		img = Image.open(BytesIO(upload_form.illust.data.read()))
		base_feature = encoder.extract_feature(img.resize((64, 64)))
		
		candidate_illust_names = Recommender.choose_illusts_from_tag(CANDIDATE_NUM, None, None)
		candidate_feature_paths = [os.path.join(FEATURE_PATH, candidate_illust_name.replace('png', 'npy')) for candidate_illust_name in candidate_illust_names]
		similarity_order = encoder.cal_similarity_order(GET_IMG_NUM, base_feature, candidate_feature_paths)
		
		illust_names = []
		for similarity_idx in similarity_order:
			illust_names.append(candidate_illust_names[similarity_idx])
		illust_paths = [os.path.join('./static/', illust_name) for illust_name in illust_names]

		if len(illust_paths) == 0:
			return render_template('no_illust.html')

		Recommender.stamp_used_img(illust_names)
		return render_template('show_illust.html', illust_paths=illust_paths)

	else:
		return render_template('illust_condition_input.html', form=upload_form)