예제 #1
0
def img2txt_ret():
    # get_vecs_knn_ret(vecs_trans[0])
    # get_feats_knn_ret(feats_trans[0])
    search_id = request.args["id"]
    print(search_id)
    # run_vgg16(sess, search_id + ".jpg")
    cat_id, imgs_id = get_feats_knn_ret(run_acmr(1, search_id))
    categories_list = [
        "art", "biology", "geography", "history", "literature", "media",
        "music", "royalty", "sport", "warfare"
    ]
    label = categories_list[cat_id - 1]
    imgs = []
    for img_id in imgs_id:
        img = {}
        temp_img = get_wikipedia_with_id(img_id)
        img["id"] = temp_img.id
        img["pic_id"] = temp_img.pic_id
        img["name"] = temp_img.name
        img["texts"] = temp_img.texts
        imgs.append(img)
    return render_template('img.html',
                           search_id=search_id,
                           label=label,
                           imgs=imgs,
                           categories_list=categories_list)
예제 #2
0
def txt2img_ret():
    query_txt = request.args["query"]
    if len(query_txt) > 0:
        cat_id, imgs_id = get_vecs_knn_ret(run_acmr(0,
                                                    extract_text(query_txt)))
        # import numpy as np
        # cat_id, imgs_id = get_vecs_knn_ret(np.fromstring(get_wikipedia_with_id(20).vecs, np.float32))
        categories_list = [
            "art", "biology", "geography", "history", "literature", "media",
            "music", "royalty", "sport", "warfare"
        ]
        label = categories_list[cat_id - 1]
        imgs = []
        for img_id in imgs_id:
            img = {}
            temp_img = get_wikipedia_with_id(img_id)
            img["id"] = temp_img.id
            img["pic_id"] = temp_img.pic_id
            img["name"] = temp_img.name
            img["texts"] = temp_img.texts
            imgs.append(img)
        return render_template('text.html',
                               query_txt=query_txt,
                               label=label,
                               imgs=imgs,
                               categories_list=categories_list)
    else:
        return make_response("异常输入~")
예제 #3
0
def detail(id):
    pedia = get_wikipedia_with_id(id)
    return render_template("detail.html",
                           name=pedia.name,
                           texts=pedia.texts,
                           pic_id=pedia.pic_id)