Ujayer commited on
Commit
bfba23c
·
verified ·
1 Parent(s): b42b559

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +163 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,165 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+ import numpy as np
6
+ from streamlit_option_menu import option_menu
7
+
8
+ # Set page config
9
+ st.set_page_config(
10
+ page_title="Movie Analytics Dashboard",
11
+ page_icon="🎬",
12
+ layout="wide",
13
+ initial_sidebar_state="expanded"
14
+ )
15
+
16
+ # Load data
17
+ @st.cache_data
18
+ def load_data():
19
+ df = pd.read_csv('watch_movies.csv')
20
+ return df
21
+
22
+ df = load_data()
23
+
24
+ # Sidebar
25
+ with st.sidebar:
26
+ st.title("🎬 Movie Analytics")
27
+ selected = option_menu(
28
+ menu_title="Navigation",
29
+ options=["Overview", "3D Analysis", "Genre Analysis", "Actor Analysis", "Recommendations"],
30
+ icons=["house", "graph-up-3d", "film", "person", "star"],
31
+ menu_icon="cast",
32
+ default_index=0,
33
+ )
34
+
35
+ # Main content
36
+ if selected == "Overview":
37
+ st.title("Movie Analytics Dashboard")
38
+
39
+ # Key metrics
40
+ col1, col2, col3, col4 = st.columns(4)
41
+ with col1:
42
+ st.metric("Total Movies", len(df))
43
+ with col2:
44
+ st.metric("Average Budget", f"${df['budget_usd'].mean():,.0f}")
45
+ with col3:
46
+ st.metric("Average User Score", f"{df['user_score'].mean():.1f}")
47
+ with col4:
48
+ st.metric("Total Genres", df['genres'].nunique())
49
+
50
+ # Budget distribution with animation
51
+ st.subheader("Budget Distribution Over Time")
52
+ fig = px.histogram(
53
+ df,
54
+ x="budget_usd",
55
+ animation_frame=pd.to_datetime(df['release_date']).dt.year,
56
+ nbins=50,
57
+ color_discrete_sequence=['#636EFA']
58
+ )
59
+ fig.update_layout(
60
+ xaxis_title="Budget (USD)",
61
+ yaxis_title="Number of Movies",
62
+ showlegend=False
63
+ )
64
+ st.plotly_chart(fig, use_container_width=True)
65
+
66
+ elif selected == "3D Analysis":
67
+ st.title("3D Movie Analysis")
68
+
69
+ # 3D scatter plot
70
+ fig = go.Figure(data=[go.Scatter3d(
71
+ x=df['budget_usd'],
72
+ y=df['vote_count'],
73
+ z=df['user_score'],
74
+ mode='markers',
75
+ marker=dict(
76
+ size=5,
77
+ color=df['user_score'],
78
+ colorscale='Viridis',
79
+ opacity=0.8
80
+ ),
81
+ text=df['title']
82
+ )])
83
+
84
+ fig.update_layout(
85
+ scene=dict(
86
+ xaxis_title="Budget (USD)",
87
+ yaxis_title="Vote Count",
88
+ zaxis_title="User Score"
89
+ ),
90
+ title="Budget vs Vote Count vs User Score"
91
+ )
92
+
93
+ st.plotly_chart(fig, use_container_width=True)
94
+
95
+ elif selected == "Genre Analysis":
96
+ st.title("Genre Analysis")
97
+
98
+ # Genre distribution
99
+ genre_counts = df['genres'].value_counts().head(10)
100
+ fig = px.bar(
101
+ x=genre_counts.values,
102
+ y=genre_counts.index,
103
+ orientation='h',
104
+ title="Top 10 Genres",
105
+ labels={'x': 'Number of Movies', 'y': 'Genre'},
106
+ color=genre_counts.values,
107
+ color_continuous_scale='Viridis'
108
+ )
109
+ st.plotly_chart(fig, use_container_width=True)
110
+
111
+ # Genre budget analysis
112
+ st.subheader("Average Budget by Genre")
113
+ genre_budget = df.groupby('genres')['budget_usd'].mean().sort_values(ascending=False).head(10)
114
+ fig = px.bar(
115
+ x=genre_budget.values,
116
+ y=genre_budget.index,
117
+ orientation='h',
118
+ title="Average Budget by Genre",
119
+ labels={'x': 'Average Budget (USD)', 'y': 'Genre'},
120
+ color=genre_budget.values,
121
+ color_continuous_scale='Viridis'
122
+ )
123
+ st.plotly_chart(fig, use_container_width=True)
124
+
125
+ elif selected == "Actor Analysis":
126
+ st.title("Actor Analysis")
127
+
128
+ # Top actors
129
+ actor_counts = df['top_billed'].value_counts().head(10)
130
+ fig = px.bar(
131
+ x=actor_counts.values,
132
+ y=actor_counts.index,
133
+ orientation='h',
134
+ title="Top 10 Actors by Movie Count",
135
+ labels={'x': 'Number of Movies', 'y': 'Actor'},
136
+ color=actor_counts.values,
137
+ color_continuous_scale='Viridis'
138
+ )
139
+ st.plotly_chart(fig, use_container_width=True)
140
 
141
+ elif selected == "Recommendations":
142
+ st.title("Movie Recommendations")
143
+
144
+ # Genre selection
145
+ selected_genre = st.selectbox("Select a genre", df['genres'].unique())
146
+
147
+ # Filter movies by genre
148
+ genre_movies = df[df['genres'] == selected_genre]
149
+
150
+ # Sort by user score
151
+ top_movies = genre_movies.sort_values('user_score', ascending=False).head(5)
152
+
153
+ # Display recommendations
154
+ for _, movie in top_movies.iterrows():
155
+ with st.container():
156
+ col1, col2 = st.columns([1, 3])
157
+ with col1:
158
+ st.image(movie['poster_path'], width=150)
159
+ with col2:
160
+ st.subheader(movie['title'])
161
+ st.write(f"User Score: {movie['user_score']:.1f}")
162
+ st.write(f"Release Date: {movie['release_date']}")
163
+ st.write(f"Director: {movie['director']}")
164
+ st.write(f"Top Billed: {movie['top_billed']}")
165
+ st.markdown("---")