Spaces:
Sleeping
Sleeping
File size: 2,679 Bytes
ef4d5d1 c3e37b9 ef4d5d1 c3e37b9 fd31c97 c3e37b9 fd31c97 c3e37b9 fd31c97 c3e37b9 fd31c97 c3e37b9 fd31c97 ab1e8ef c3e37b9 ab1e8ef c3e37b9 ab1e8ef c3e37b9 ab1e8ef fd31c97 c3e37b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
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}')
|