Movie Recommendation system with Jupyter and Anvil

What I’m trying to do:
I am building a movie recommendation system with Jupyter but now i would like to use Anvil as my user interface .

What I’ve tried and what’s not working:
I have tried to link it with the uplink and pip installed anvil, but my biggest problem is the coding aspect. I dont know what i am doing wrong…somebody help me pleaseeeeeeeee…what am i doing wrong!
So i imported a .csv table from excel with movies and ratings, using cosine similarity which i imported into jupyter, i want to recommend movies to people using the movie title’ they input in Anvil and show them their recommendations on anvil not on Jupyter.

Code Sample:

# code snippet
import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import CountVectorizer

df = pd.read_csv(r"C:\Users\Administrator\Desktop\Movie_data.csv")

columns = ['Actors', 'Director', 'Genre', 'Title']


def get_important_features(data):
    important_features = []
    for i in range(0, data.shape[0]):
        important_features.append(
            data['Actors'][i] + ' ' + data['Director'][i] + ' ' + data['Genre'][i] + ' ' + data['Title'][i])

    return important_features
    df['important_features'] = get_important_features(df)
    cm = CountVectorizer().fit_transform(df['important_features'])
    cs = cosine_similarity(cm)


title = input()

movie_id = df[df.Title == title]['Rank'].values[0]
scores = list(enumerate(cs[movie_id]))
sorted_scores = sorted(scores, key=lambda x: x[1], reverse=True)
sorted_scores = sorted_scores[1:]
```import anvil.server

anvil.server.connect("R6SRBVR4NBPZCVOG6DCMY7NL-6RH3VF3YI5END64F")

@anvil.server.callable
def here(title):
    j=0
    print('The top 10 most recommended movies to', title, 'are:\n')
    for item in sorted_scores:
        movie_title= df[df.Rank == item[0]]['Title'].values[0]
        b=j+1, movie_title
        print(b)
        j= j+1
        if j>9:
            break
            return b
    
anvil.server.wait_forever() 


Clone link:
*share a copy of your app*
https://anvil.works/build#clone:6RH3VF3YI5END64F=PXCH46JSQXKLIDSXXM5FXY4K

Hi @fustieorazu, welcome to the Anvil community!

Your code looks broadly reasonable, but it’s not quite clear exactly what you want its behaviour to be. Please could you let me know what it’s doing now, and what you would like it to do? For example, what exactly do you want your here(...) function to return? What does it actually return right now?

i want the system to return a list of movies based on the input of the user .
so a user, inputs a movie title, the movie title runs through a database using the cosine similarity formular and then a list of similar movies are recommended to the user.

Hi @fustieorazu

That high-level description makes sense, and sounds like a good plan. My question was about the code you have so far - What does your here() function return? And what would you like it to return?

right now, it is not returning anything, however, i will like it to send whatever is in it to my Anvil server.

I dont think i wrote the def function right