Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from course_project import constants | |
| from course_project.application_tools import get_data, get_recommendations, get_connections, get_explanation_for_reco | |
| # brew install ollama | |
| # ollama run gemma:7b | |
| # Load app with: streamlit run course_project/app.py | |
| # Cargar los datos de películas para mostrar en la interfaz | |
| movies_data = get_data() | |
| movies_titles = movies_data['title'].tolist() | |
| movies_ids = movies_data.index.tolist() | |
| movies_dict = dict(zip(movies_titles, movies_ids)) | |
| st.title('Movie Recommendation System') | |
| # Sección para Javier | |
| st.header('User 1\'s Movie Suggestions') | |
| user_1_selections = st.multiselect('Select movies for User 1', movies_titles) | |
| # Sección para Amelia | |
| st.header('User 2\'s Movie Suggestions') | |
| user_2_selections = st.multiselect('Select movies for User 2', movies_titles) | |
| # Convertir las selecciones de títulos a IDs | |
| user_1_ids = [movies_dict[title] for title in user_1_selections] | |
| user_2_ids = [movies_dict[title] for title in user_2_selections] | |
| # Crear el diccionario de suggestions | |
| suggestions = { | |
| "User1": user_1_ids, | |
| "User2": user_2_ids | |
| } | |
| # Widget para seleccionar el número de resultados | |
| n_results = st.number_input('Number of recommendations', min_value=1, max_value=100, value=10) | |
| # Widget para seleccionar el método de similitud | |
| similarity_method = st.radio("Select Similarity Method", ["Euclidean Similarity", "Cosine Similarity"]) | |
| # Asignar el valor de la constante apropiada basado en la selección del usuario | |
| if similarity_method == "Cosine Similarity": | |
| similarity = constants.COSINE_SIMILARITY | |
| else: | |
| similarity = constants.EUCLIDEAN_SIMILARITY | |
| if st.button('Get Recommendations'): | |
| recommendations_df = get_recommendations(suggestions, n_results=n_results, similarity=similarity) | |
| st.session_state.recommendations_df = recommendations_df | |
| if 'recommendations_df' in st.session_state: | |
| recommendations_df = st.session_state.recommendations_df | |
| for index, row in recommendations_df.iterrows(): | |
| st.markdown(f'## {row["title"]}') | |
| st.image(row["poster_path"]) | |
| st.markdown(row["overview"]) | |
| st.markdown(f'Recommended because of the following related requests:') | |
| connections = get_connections(row) | |
| for person, request in connections.items(): | |
| st.markdown(f'**{person}**: {request}') | |
| # if st.button(f'Get Explanation for Recommendation {row["title"]}', key=f'btn-{index}'): | |
| # suggestion_ids = [id for id in row["based_on_index"].values()] | |
| # reason = get_explanation_for_reco(suggestion_ids[0], suggestion_ids[1], index) | |
| # st.markdown(f'**Reason for recommendation**: {reason}') | |