代码如下-
import streamlit as st
import pickle
import pandas as pd
def recommend(movie):
movie_index = movies[movies['title'] == movie].index[0]
distances = similarity[movie_index]
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
recommended_movies = []
for i in movies_list:
recommended_movies.append(print(movies.iloc[i[0]].title))
return recommended_movies
movies_dict = pickle.load(open('movie_dict.pkl', 'rb'))
movies = pd.DataFrame(movies_dict)
similarity = pickle.load(open('similarity.pkl', 'rb'))
st.title('Movie Recommender System')
selected_movie_name = st.selectbox(
'Hey ! Wanna watch a movie ? Tell us the last movie you watched -',
movies['title'].values)
if st.button('Recommend'):
recommendations = recommend(selected_movie_name)
for i in recommendations :
st.write(i) #### This is what i'm talking about
我试过其他的选择,如sttext或stmarkdown,但没有一个是工作的,它显示没有每一次
1条答案
按热度按时间3wabscal1#
如注解中所述,您需要在不调用print的情况下进行追加,例如: