elozano commited on
Commit
c0b28bb
·
1 Parent(s): 8d0b477

small changes

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -7,6 +7,10 @@ from utils import get_index, get_movie_info
7
  MAX_OVERVIEW_LENGTH = 280
8
  IMAGE_WIDTH = 170
9
 
 
 
 
 
10
 
11
  @st.cache()
12
  def init() -> None:
@@ -21,14 +25,17 @@ def run() -> None:
21
  with st.form("search"):
22
  title = st.selectbox("Recommend movies based on:", st.session_state["titles"])
23
  num_recommendations = st.number_input(
24
- "Number of recommendations:", min_value=1, max_value=20, value=6
 
 
 
25
  )
26
  search = st.form_submit_button("Search")
27
  if search:
28
- recommend(title, num_recommendations)
29
 
30
 
31
- def recommend(based_on: str, num_recommendations: int) -> None:
32
  movie_index = get_index(based_on)
33
  similarities = list(enumerate(st.session_state["sim_matrix"][movie_index]))
34
  similarities.pop(movie_index)
@@ -36,10 +43,10 @@ def recommend(based_on: str, num_recommendations: int) -> None:
36
  recommendations = sorted_similarities[:num_recommendations]
37
  st.markdown("---")
38
  for idx, _ in recommendations:
39
- show_movie_info(idx)
40
 
41
 
42
- def show_movie_info(movie_index: str) -> None:
43
  info = get_movie_info(movie_index)
44
  im_col, info_col = st.columns([2, 4])
45
  im_col.image(
 
7
  MAX_OVERVIEW_LENGTH = 280
8
  IMAGE_WIDTH = 170
9
 
10
+ MIN_RECOMMENDATIONS = 1
11
+ MAX_RECOMMENDATIONS = 100
12
+ DEFAULT_RECOMMENDATIONS = 10
13
+
14
 
15
  @st.cache()
16
  def init() -> None:
 
25
  with st.form("search"):
26
  title = st.selectbox("Recommend movies based on:", st.session_state["titles"])
27
  num_recommendations = st.number_input(
28
+ "Number of recommendations:",
29
+ min_value=MIN_RECOMMENDATIONS,
30
+ max_value=MAX_RECOMMENDATIONS,
31
+ value=DEFAULT_RECOMMENDATIONS,
32
  )
33
  search = st.form_submit_button("Search")
34
  if search:
35
+ _recommend(title, num_recommendations)
36
 
37
 
38
+ def _recommend(based_on: str, num_recommendations: int) -> None:
39
  movie_index = get_index(based_on)
40
  similarities = list(enumerate(st.session_state["sim_matrix"][movie_index]))
41
  similarities.pop(movie_index)
 
43
  recommendations = sorted_similarities[:num_recommendations]
44
  st.markdown("---")
45
  for idx, _ in recommendations:
46
+ _show_movie_info(idx)
47
 
48
 
49
+ def _show_movie_info(movie_index: str) -> None:
50
  info = get_movie_info(movie_index)
51
  im_col, info_col = st.columns([2, 4])
52
  im_col.image(