Contents
Creating the Interface Function
This lesson focuses on creating a function that connects user input with the recommendation system. Gradio works by calling a Python function whenever the user submits input, so this function acts as the core bridge between the UI and the KNN-based recommender.
Code:
def recommend_interface_html(title):
try:
recommendations = recommend_movie_knn(title, n=10)
simplified = recommendations[['Title','Avg Rating']]
return simplified.to_html(index=False, border=1)
except Exception as e:
return f"<p style='color:red;'>Error: {str(e)}</p>"
Here, the function accepts a movie title entered by the user. It internally calls the already-built recommend_movie_knn function, which performs genre similarity matching and hybrid scoring. To keep the interface simple and readable, only the movie title and average rating are displayed. The output is converted into an HTML table so that Gradio can render it cleanly. Error handling ensures that invalid inputs do not crash the application and instead show a helpful message.










