lekimngan3010 commited on
Commit
569ef62
·
verified ·
1 Parent(s): 2c5feef

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -10
src/streamlit_app.py CHANGED
@@ -9,11 +9,9 @@ st.set_page_config(layout="wide", page_title="IMDb Cinematic Trends")
9
  # Enable Altair Dark Theme for visibility on black backgrounds
10
  alt.themes.enable('dark')
11
 
12
- # Data Loading (Cached for Speed)
13
  @st.cache_data
14
  def load_all_data():
15
- # Using relative paths
16
- # If files are in a 'src' folder, we check there first
17
  main_path = 'src/merged_imdb_sample.csv' if os.path.exists('src/merged_imdb_sample.csv') else 'merged_imdb_sample.csv'
18
  ctx_path = 'src/principals_context_sample.csv' if os.path.exists('src/principals_context_sample.csv') else 'principals_context_sample.csv'
19
 
@@ -75,8 +73,6 @@ genres and decades, along with the top directors for them, and how those ratings
75
  st.header("1. Interactive Trend Explorer")
76
  st.info("💡 **Interaction:** Click a cell in the Heatmap to filter the Top Directors chart below.")
77
 
78
- # 1. Define selection WITHOUT a default value (prevents the Schema Error)
79
- # 'toggle=False' makes it so clicking outside doesn't clear the selection
80
  selection = alt.selection_point(
81
  fields=['genre_list', 'decade'],
82
  name='cell',
@@ -99,15 +95,17 @@ heatmap = alt.Chart(df).mark_rect().encode(
99
  title="Average Movie Ratings by Genre and Decade"
100
  ).add_params(selection)
101
 
102
- # 3. Bar Chart with "Fallback" Logic
 
103
  bar_chart = alt.Chart(df).mark_bar().encode(
 
104
  x=alt.X('total_votes:Q', title='Total Popularity (Votes)'),
105
  y=alt.Y('directorName:N', sort='-x', title='Director', axis=alt.Axis(labelLimit=200)),
106
  color=alt.value('#4682B4'),
107
- tooltip=['directorName', 'sum(numVotes)']
108
- ).transform_filter(
109
- # If nothing is selected, this filter now returns TRUE for everything
110
- selection
111
  ).transform_aggregate(
112
  total_votes='sum(numVotes)',
113
  groupby=['directorName']
@@ -148,6 +146,7 @@ It suggests that movie records are not only about the films themselves, but also
148
  contributors, such as actors, actresses, directors, and writers, are presented to the public.
149
  """)
150
 
 
151
  # Contextual Charts
152
  st.header("2. Production Context")
153
  ctx_col1, ctx_col2 = st.columns(2)
@@ -178,6 +177,8 @@ with ctx_col2:
178
  st.altair_chart(collab_density, use_container_width=True)
179
  st.caption("Source: IMDb Principals Sample. Most successful films require 10-25 key leaders.")
180
 
 
 
181
  # Narrative Paragraph
182
  st.markdown("""
183
  ### The Final Story: Complexity and Quality
 
9
  # Enable Altair Dark Theme for visibility on black backgrounds
10
  alt.themes.enable('dark')
11
 
12
+ # Data Loading
13
  @st.cache_data
14
  def load_all_data():
 
 
15
  main_path = 'src/merged_imdb_sample.csv' if os.path.exists('src/merged_imdb_sample.csv') else 'merged_imdb_sample.csv'
16
  ctx_path = 'src/principals_context_sample.csv' if os.path.exists('src/principals_context_sample.csv') else 'principals_context_sample.csv'
17
 
 
73
  st.header("1. Interactive Trend Explorer")
74
  st.info("💡 **Interaction:** Click a cell in the Heatmap to filter the Top Directors chart below.")
75
 
 
 
76
  selection = alt.selection_point(
77
  fields=['genre_list', 'decade'],
78
  name='cell',
 
95
  title="Average Movie Ratings by Genre and Decade"
96
  ).add_params(selection)
97
 
98
+
99
+ # 3. Bar Chart
100
  bar_chart = alt.Chart(df).mark_bar().encode(
101
+ # Use the aggregated field name here
102
  x=alt.X('total_votes:Q', title='Total Popularity (Votes)'),
103
  y=alt.Y('directorName:N', sort='-x', title='Director', axis=alt.Axis(labelLimit=200)),
104
  color=alt.value('#4682B4'),
105
+ # Changed 'sum(numVotes)' to 'total_votes'
106
+ tooltip=['directorName', alt.Tooltip('total_votes:Q', format=',')]
107
+ ).transform_filter(
108
+ selection # Ensure 'selection' is defined above this block!
109
  ).transform_aggregate(
110
  total_votes='sum(numVotes)',
111
  groupby=['directorName']
 
146
  contributors, such as actors, actresses, directors, and writers, are presented to the public.
147
  """)
148
 
149
+
150
  # Contextual Charts
151
  st.header("2. Production Context")
152
  ctx_col1, ctx_col2 = st.columns(2)
 
177
  st.altair_chart(collab_density, use_container_width=True)
178
  st.caption("Source: IMDb Principals Sample. Most successful films require 10-25 key leaders.")
179
 
180
+
181
+
182
  # Narrative Paragraph
183
  st.markdown("""
184
  ### The Final Story: Complexity and Quality