Penguni commited on
Commit
9583c19
·
verified ·
1 Parent(s): 26347e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -77,7 +77,7 @@ def fetch_and_plot_average_rating_by_genre(conn):
77
  return fig
78
 
79
  # Function to create word cloud of genres
80
- def create_genre_wordcloud(conn):
81
  query = r'''
82
  SELECT genres
83
  FROM title_basics
@@ -89,14 +89,17 @@ def create_genre_wordcloud(conn):
89
  genres = df['genres'].str.split(',', expand=True).stack().replace('\\N', pd.NA).dropna().reset_index(drop=True)
90
  genre_counts = Counter(genres)
91
 
92
- # Generate the word cloud
93
- wordcloud = WordCloud(width=800, height=400, colormap='inferno').generate_from_frequencies(genre_counts)
 
 
 
94
 
95
  # Display the word cloud
96
  plt.figure(figsize=(10, 5))
97
  plt.imshow(wordcloud, interpolation='bilinear')
98
  plt.axis('off')
99
- st.pyplot(plt.gcf())
100
 
101
  # Function to find best movie of each genre by numVotes * averageRating
102
  def find_best_movies_by_genre(conn):
@@ -299,7 +302,7 @@ def run_app():
299
  st.dataframe(best_movies_by_genre)
300
 
301
  with col2:
302
- create_genre_wordcloud(conn)
303
 
304
  with col3:
305
  st.subheader('Average Rating by Genre')
 
77
  return fig
78
 
79
  # Function to create word cloud of genres
80
+ def create_genre_wordcloud(conn, mask_path):
81
  query = r'''
82
  SELECT genres
83
  FROM title_basics
 
89
  genres = df['genres'].str.split(',', expand=True).stack().replace('\\N', pd.NA).dropna().reset_index(drop=True)
90
  genre_counts = Counter(genres)
91
 
92
+ # Load the mask image
93
+ mask = imageio.imread(mask_path)
94
+
95
+ # Generate the word cloud with the mask
96
+ wordcloud = WordCloud(width=800, height=400, background_color='white', mask=mask).generate_from_frequencies(genre_counts)
97
 
98
  # Display the word cloud
99
  plt.figure(figsize=(10, 5))
100
  plt.imshow(wordcloud, interpolation='bilinear')
101
  plt.axis('off')
102
+ st.pyplot(plt.gcf())
103
 
104
  # Function to find best movie of each genre by numVotes * averageRating
105
  def find_best_movies_by_genre(conn):
 
302
  st.dataframe(best_movies_by_genre)
303
 
304
  with col2:
305
+ create_genre_wordcloud(conn, 'mask.png')
306
 
307
  with col3:
308
  st.subheader('Average Rating by Genre')