Penguni commited on
Commit
da142a4
·
verified ·
1 Parent(s): b7ae97f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -9,11 +9,13 @@ from collections import Counter
9
  import numpy as np
10
 
11
  # Function to load data from SQLite database
 
12
  def load_data(db_file):
13
  conn = sqlite3.connect(db_file)
14
  return conn
15
 
16
  # Function to fetch genre movie releases by year
 
17
  def fetch_genre_movie_releases(conn):
18
  query = r'''
19
  SELECT startYear, genres
@@ -35,6 +37,7 @@ def fetch_genre_movie_releases(conn):
35
  return genre_counts
36
 
37
  # Function to fetch data for filled line chart of movie release years
 
38
  def fetch_movie_release_years(conn):
39
  query_release_years = r'''
40
  SELECT startYear, COUNT(*) as count
@@ -47,6 +50,7 @@ def fetch_movie_release_years(conn):
47
  return df_release_years
48
 
49
  # Function to fetch data and create box plot of average rating by first_genre
 
50
  def fetch_and_plot_average_rating_by_genre(conn):
51
  query = r'''
52
  SELECT tb.tconst, tb.primaryTitle, tr.averageRating, tb.genres
@@ -57,7 +61,7 @@ def fetch_and_plot_average_rating_by_genre(conn):
57
  df = pd.read_sql_query(query, conn)
58
 
59
  # Function to extract the first genre from the genres list
60
- def extract_first_genre(genres):
61
  if genres:
62
  return genres.split(',')[0].strip()
63
  else:
@@ -103,6 +107,7 @@ def create_genre_wordcloud(conn):
103
  st.pyplot(plt.gcf()) # Pass the current figure explicitly to st.pyplot()
104
 
105
  # Function to find best movie of each genre by numVotes * averageRating
 
106
  def find_best_movies_by_genre(conn):
107
  query = r'''
108
  SELECT tb.tconst, tb.primaryTitle, tb.startYear, tb.genres, tr.averageRating, tr.numVotes
@@ -126,6 +131,7 @@ def find_best_movies_by_genre(conn):
126
  return best_movies_by_genre
127
 
128
  # Function to plot stacked area chart of genre movie releases by year using Plotly Express
 
129
  def plot_stacked_genre_movie_releases(genre_counts):
130
  fig = px.area(genre_counts, x='startYear', y='count', color='genres',
131
  title='Stacked Genre Movie Releases by Year',
@@ -146,6 +152,7 @@ def plot_stacked_genre_movie_releases(genre_counts):
146
  return fig
147
 
148
  # Function to plot global map of total films per region using Plotly Express
 
149
  def plot_global_map():
150
  df = pd.read_csv('movie_region.csv')
151
  # Country code to name mapping
@@ -241,6 +248,7 @@ def plot_global_map():
241
 
242
 
243
  # Function to fetch summary info
 
244
  def fetch_summary_info(conn):
245
  # Fetch total count of movies
246
  query_total_movies = r'''
 
9
  import numpy as np
10
 
11
  # Function to load data from SQLite database
12
+ @st.cache_data
13
  def load_data(db_file):
14
  conn = sqlite3.connect(db_file)
15
  return conn
16
 
17
  # Function to fetch genre movie releases by year
18
+ @st.cache_data
19
  def fetch_genre_movie_releases(conn):
20
  query = r'''
21
  SELECT startYear, genres
 
37
  return genre_counts
38
 
39
  # Function to fetch data for filled line chart of movie release years
40
+ @st.cache_data
41
  def fetch_movie_release_years(conn):
42
  query_release_years = r'''
43
  SELECT startYear, COUNT(*) as count
 
50
  return df_release_years
51
 
52
  # Function to fetch data and create box plot of average rating by first_genre
53
+ @st.cache_data
54
  def fetch_and_plot_average_rating_by_genre(conn):
55
  query = r'''
56
  SELECT tb.tconst, tb.primaryTitle, tr.averageRating, tb.genres
 
61
  df = pd.read_sql_query(query, conn)
62
 
63
  # Function to extract the first genre from the genres list
64
+ def extract_first_genre(genres):
65
  if genres:
66
  return genres.split(',')[0].strip()
67
  else:
 
107
  st.pyplot(plt.gcf()) # Pass the current figure explicitly to st.pyplot()
108
 
109
  # Function to find best movie of each genre by numVotes * averageRating
110
+ @st.cache_data
111
  def find_best_movies_by_genre(conn):
112
  query = r'''
113
  SELECT tb.tconst, tb.primaryTitle, tb.startYear, tb.genres, tr.averageRating, tr.numVotes
 
131
  return best_movies_by_genre
132
 
133
  # Function to plot stacked area chart of genre movie releases by year using Plotly Express
134
+ @st.cache_data
135
  def plot_stacked_genre_movie_releases(genre_counts):
136
  fig = px.area(genre_counts, x='startYear', y='count', color='genres',
137
  title='Stacked Genre Movie Releases by Year',
 
152
  return fig
153
 
154
  # Function to plot global map of total films per region using Plotly Express
155
+ @st.cache_data
156
  def plot_global_map():
157
  df = pd.read_csv('movie_region.csv')
158
  # Country code to name mapping
 
248
 
249
 
250
  # Function to fetch summary info
251
+ @st.cache_data
252
  def fetch_summary_info(conn):
253
  # Fetch total count of movies
254
  query_total_movies = r'''