Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -109,7 +109,10 @@ def fetch_and_plot_average_rating_by_genre(conn):
|
|
109 |
return fig
|
110 |
|
111 |
# Function to create word cloud of genres
|
112 |
-
def
|
|
|
|
|
|
|
113 |
query = r'''
|
114 |
SELECT genres
|
115 |
FROM title_basics
|
@@ -121,11 +124,19 @@ def create_genre_wordcloud(conn, mask_path):
|
|
121 |
genres = df['genres'].str.split(',', expand=True).stack().replace('\\N', pd.NA).dropna().reset_index(drop=True)
|
122 |
genre_counts = Counter(genres)
|
123 |
|
124 |
-
#
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
# Display the word cloud
|
128 |
-
plt.figure(figsize=(10,
|
129 |
plt.imshow(wordcloud, interpolation='bilinear')
|
130 |
plt.axis('off')
|
131 |
st.pyplot(plt.gcf())
|
|
|
109 |
return fig
|
110 |
|
111 |
# Function to create word cloud of genres
|
112 |
+
def genre_color_func(word, font_size, position, orientation, random_state=None, **kwargs):
|
113 |
+
return genre_color_map.get(word, '#FFFFFF') # Default to white if genre is not in the map
|
114 |
+
|
115 |
+
def create_genre_wordcloud(conn):
|
116 |
query = r'''
|
117 |
SELECT genres
|
118 |
FROM title_basics
|
|
|
124 |
genres = df['genres'].str.split(',', expand=True).stack().replace('\\N', pd.NA).dropna().reset_index(drop=True)
|
125 |
genre_counts = Counter(genres)
|
126 |
|
127 |
+
# Create a circular mask
|
128 |
+
mask = np.zeros((800, 800), dtype=np.uint8)
|
129 |
+
center_x, center_y = 400, 400
|
130 |
+
radius = 400
|
131 |
+
y, x = np.ogrid[:800, :800]
|
132 |
+
mask_area = (x - center_x)**2 + (y - center_y)**2 <= radius**2
|
133 |
+
mask[mask_area] = 255
|
134 |
+
|
135 |
+
# Generate the word cloud with the circular mask and custom colors
|
136 |
+
wordcloud = WordCloud(width=800, height=800, background_color='white', mask=mask, color_func=genre_color_func).generate_from_frequencies(genre_counts)
|
137 |
|
138 |
# Display the word cloud
|
139 |
+
plt.figure(figsize=(10, 10))
|
140 |
plt.imshow(wordcloud, interpolation='bilinear')
|
141 |
plt.axis('off')
|
142 |
st.pyplot(plt.gcf())
|