Esempio n. 1
0
def recommend_view():
    num_of_films_to_recommend = request.args.get("num")
    likes = request.args.get("likes").strip("[]").split(",")
    likes = list(map(lambda x: x.replace('"', '').strip(), likes))

    if any(map(lambda x: not x.isnumeric(), list(num_of_films_to_recommend))):
        return {"error": "Number of recommendations is not a number."}
    elif num_of_films_to_recommend is None:
        return {"error": "Provide number of films to recommend."}
    elif likes is None:
        return {"error": "Provide names of films, that user already likes."}
    else:
        bad_films = list(filter(invalid, likes))
        if len(bad_films) != 0:
            return {
                "error":
                f"This version of app don`t knows about some films you passed.",
                "unknown_films": bad_films
            }
        else:
            likes_ids = list(map(lambda x: MOVIE_TO_NETFLIX_ID_DICT[x], likes))
            num_of_films_to_recommend = int(num_of_films_to_recommend)
            recommendation = get_recommendations(likes_ids,
                                                 num_of_films_to_recommend)
            return {"status": "ok", "recommendations": recommendation}
Esempio n. 2
0
def home():

    # print(request.data)
    req_data = request.get_json()
    movie_name = req_data['movie']
    recommend_movies = json.dumps(model.get_recommendations(movie_name))
    return jsonify({"movies_data": recommend_movies})
Esempio n. 3
0
def update_output_rec(n_clicks, value):
    value = value.replace('https://www.trailforks.com/trails/', '')
    value = value.replace('/', '')
    reclist, input_row = get_recommendations(trail_data_clean, value, indices,
                                             cosine_sim)
    reclist = shrink_table(reclist, trail_data)
    input_row = shrink_table(input_row, trail_data)
    return generate_tables(reclist, input_row)
Esempio n. 4
0
def recommendations():
    if (request.method == 'POST'):
        user_id = request.form.get('user_id')
        print("USER ID is " + user_id)
        output = model.get_recommendations(user_id)
        return render_template('view.html',
                               recommendation_text='{}'.format(output))
    else:
        return render_template('view.html')
def recommend():

    # print(request)
    obj = request.json
    print(str(obj['title']))

    ans = get_recommendations(str(obj['title']))
    ans2 = serialize(ans)

    return (jsonify(ans2))
Esempio n. 6
0
def feed():
    try:
        json_ = request.json

        recommendations_feed = get_recommendations(title=json_["title"])

        return recommendations_feed

    except:

        return jsonify({'trace': traceback.format_exc()})
Esempio n. 7
0
def predict():
    if request.method == 'POST':
        global inf2
        mov_name = request.form['movie']
        rat = request.form['rating']
        #print(mov)
        mov = get_id(mov_name)

        mov2 = zip([int(mov)], [int(rat)])
        f = get_recommendations(mov2)

        inf = get(f)

    return render_template('index.html', result=inf)
Esempio n. 8
0
def recommend_movies_to_user():
    """
    Accept json={username:username, num_result:num}
    Return num movie ids json_array
    """

    data = request.get_json()
    print(data)
    uname = data['username']

    check = server.check_user(uname)
    if not check:
        status = 903
        responsemessage = "Username doesn't exist"
        recc_tmdb_ids, recc_movie_names = [], []
    else:
        try:
            tmdb_ids, ratings = server.get_user_movies_n_ratings(uname)
            movie_ids = server.get_movie_ids(tmdb_ids)
            recc_movie_ids = model.get_recommendations(
                utils.get_zipped(movie_ids, ratings))
            if type(recc_movie_ids) is str:  # KeyError
                status = 601
                responsemessage = "Insufficient Ratings"
                recc_tmdb_ids, recc_movie_names = [], []
            else:  # All OK
                status = 200
                responsemessage = "ok"
                recc_tmdb_ids = server.get_tmdb_ids(recc_movie_ids)
                recc_movie_names = server.get_movie_names(recc_movie_ids)
        except ValueError:  # User had not rated movies yet
            status = 703
            responsemessage = "History not available"
            recc_tmdb_ids, recc_movie_names = [], []

    data = {
        'responsecode': status,
        'responsemessage': responsemessage,
        'tmdb_ids': recc_tmdb_ids,
        'names': recc_movie_names
    }
    print(data)
    data = json.dumps(data)
    return data
Esempio n. 9
0
def movies_similar_to():
    """
    Accept json={movie_array:imdb ids json_array, num_result:num}
    Return num movie ids json_array
    """

    data = request.get_json()
    print(data)
    tmdb_ids, num_rec = data['tmdb_ids'], data['num_result']

    movie_ids = server.get_movie_ids(tmdb_ids)
    recc_movie_ids = model.get_recommendations(movie_ids)

    if type(recc_movie_ids) is str:
        return "insufficient_ratings"

    recc_tmdb_ids = server.get_tmdb_ids(recc_movie_ids)
    recc_movie_names = server.get_movie_names(recc_movie_ids)

    data = {'tmdb_ids': recc_tmdb_ids, 'names': recc_movie_names}
    print(data)
    data = json.dumps(data)
    return data