Moiz commited on
Commit
ebe8012
Β·
1 Parent(s): a7c3fd9

added functionality to rate movies

Browse files
Files changed (3) hide show
  1. MovieDatabase.csv +0 -0
  2. app.py +112 -24
  3. styles.css +26 -3
MovieDatabase.csv CHANGED
The diff for this file is too large to render. See raw diff
 
app.py CHANGED
@@ -5,8 +5,14 @@ import pandas as pd
5
  # Load the dataset
6
  data = pd.read_csv('MovieDatabase.csv')
7
 
8
- # Initialize the current index
 
 
 
 
 
9
  current_index = [0]
 
10
 
11
  def encode_image(image_path):
12
  with open(image_path, "rb") as img_file:
@@ -17,30 +23,37 @@ imdb_logo = encode_image("assets/imdblogo.png")
17
  rotten_logo = encode_image("assets/rotten.png")
18
  metacritic_logo = encode_image("assets/metacritic.png")
19
 
20
- def display_movie(action):
 
 
 
21
  # Update the index based on action
22
  if action == "next" and current_index[0] < len(data) - 1:
23
  current_index[0] += 1
24
  elif action == "prev" and current_index[0] > 0:
25
  current_index[0] -= 1
26
-
27
  # Extract movie details
28
  movie = data.iloc[current_index[0]]
 
 
 
 
29
  details = {
30
- "title": f"# {movie['Title']}",
31
  "poster_placeholder": "πŸŽ₯ Movie Poster Placeholder πŸŽ₯",
32
  "ratings": f"""
33
- <div style="display: flex; gap: 15px; align-items: center;">
34
- <div style="text-align: center;">
35
- <img src="{imdb_logo}" alt="IMDb" style="width: 40px; height: auto;"/>
36
  <p>{movie['IMDb']}</p>
37
  </div>
38
- <div style="text-align: center;">
39
- <img src="{rotten_logo}" alt="Rotten Tomatoes" style="width: 40px; height: auto;"/>
40
  <p>{movie['Rotten Tomatoes']}</p>
41
  </div>
42
- <div style="text-align: center;">
43
- <img src="{metacritic_logo}" alt="Metascore" style="width: 40px; height: auto;"/>
44
  <p>{movie['Metascore']}</p>
45
  </div>
46
  </div>
@@ -55,37 +68,112 @@ def display_movie(action):
55
  **Plot:** {movie['Plot']}
56
  **Awards:** {movie['Awards']}
57
  **Box Office:** {movie['BoxOffice']}
58
- """
 
 
59
  }
60
- return details["title"], details["poster_placeholder"], details["ratings"], details["details"]
 
 
 
 
 
 
61
 
62
- # Define Gradio interface
63
- with gr.Blocks() as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  gr.Markdown("## 🎬 Movie Database Viewer 🎬")
65
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  with gr.Row():
67
  with gr.Column(scale=1):
68
  poster = gr.Markdown("πŸŽ₯ Movie Poster Placeholder πŸŽ₯", elem_id="poster")
69
  with gr.Column(scale=2):
70
- title = gr.Markdown("# Title Placeholder", elem_id="title")
71
  ratings = gr.HTML("<div style='text-align: center;'>Ratings Placeholder</div>", elem_id="ratings")
72
  movie_details = gr.Markdown("Details will appear here.", elem_id="details")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  with gr.Row():
75
- prev_button = gr.Button("⬅️ Previous")
76
- next_button = gr.Button("Next ➑️")
 
 
 
 
 
77
 
78
  # Interactivity for buttons
 
 
 
 
 
 
79
  prev_button.click(
80
  display_movie,
81
- inputs=gr.Text(value="prev", visible=False),
82
- outputs=[title, poster, ratings, movie_details]
83
  )
84
  next_button.click(
85
  display_movie,
86
- inputs=gr.Text(value="next", visible=False),
87
- outputs=[title, poster, ratings, movie_details]
 
 
 
 
 
 
 
 
 
 
 
88
  )
89
 
90
- # Launch the app
91
  app.launch()
 
5
  # Load the dataset
6
  data = pd.read_csv('MovieDatabase.csv')
7
 
8
+ # Add a default column for ratings if not already present
9
+ for profile in ['moiz', 'udisha', 'musab']:
10
+ if profile not in data.columns:
11
+ data[profile] = "" # Default rating is empty
12
+
13
+ # Save the current index and selected profile
14
  current_index = [0]
15
+ current_profile = ["moiz"] # Default profile
16
 
17
  def encode_image(image_path):
18
  with open(image_path, "rb") as img_file:
 
23
  rotten_logo = encode_image("assets/rotten.png")
24
  metacritic_logo = encode_image("assets/metacritic.png")
25
 
26
+ def display_movie(action, profile):
27
+ # Update the current profile
28
+ current_profile[0] = profile
29
+
30
  # Update the index based on action
31
  if action == "next" and current_index[0] < len(data) - 1:
32
  current_index[0] += 1
33
  elif action == "prev" and current_index[0] > 0:
34
  current_index[0] -= 1
35
+
36
  # Extract movie details
37
  movie = data.iloc[current_index[0]]
38
+
39
+ # Get the IMDb ID from the 'id' column
40
+ movie_id = movie.get('id', 'Unknown') # Use 'Unknown' if 'id' doesn't exist
41
+
42
  details = {
43
+ "title": f'<a href="https://www.imdb.com/title/{movie_id}/" target="_blank" style="font-size: 36px; text-decoration: none; color: inherit; font-family: Arial, sans-serif;">{movie["Title"]}</a>',
44
  "poster_placeholder": "πŸŽ₯ Movie Poster Placeholder πŸŽ₯",
45
  "ratings": f"""
46
+ <div style="display: flex; gap: 15px; align-items: center; text-align: center;">
47
+ <div>
48
+ <img src="{imdb_logo}" alt="IMDb" style="width: 30px; height: auto;"/>
49
  <p>{movie['IMDb']}</p>
50
  </div>
51
+ <div>
52
+ <img src="{rotten_logo}" alt="Rotten Tomatoes" style="width: 30px; height: auto;"/>
53
  <p>{movie['Rotten Tomatoes']}</p>
54
  </div>
55
+ <div>
56
+ <img src="{metacritic_logo}" alt="Metascore" style="width: 30px; height: auto;"/>
57
  <p>{movie['Metascore']}</p>
58
  </div>
59
  </div>
 
68
  **Plot:** {movie['Plot']}
69
  **Awards:** {movie['Awards']}
70
  **Box Office:** {movie['BoxOffice']}
71
+ """,
72
+ "current_rating": f"Your Rating: {movie[profile]}",
73
+ "index_display": f'<span class="index-display">{current_index[0] + 1}/{len(data)}</span>' # Class applied for index
74
  }
75
+ return details["title"], details["poster_placeholder"], details["ratings"], details["details"], details["current_rating"], details["index_display"]
76
+
77
+ def submit_rating(rating):
78
+ # Update the rating for the current profile and movie
79
+ movie_index = current_index[0]
80
+ profile = current_profile[0]
81
+ data.at[movie_index, profile] = rating
82
 
83
+ # Save the changes to the CSV
84
+ data.to_csv('MovieDatabase.csv', index=False)
85
+
86
+ return display_movie("stay", profile)
87
+
88
+ def not_watched():
89
+ # Mark the movie as "N/W" for the current profile
90
+ movie_index = current_index[0]
91
+ profile = current_profile[0]
92
+ data.at[movie_index, profile] = "N/W"
93
+
94
+ # Save the changes to the CSV
95
+ data.to_csv('MovieDatabase.csv', index=False)
96
+
97
+ return display_movie("stay", profile)
98
+
99
+ # Define Gradio interface with external CSS file
100
+ with gr.Blocks(css_paths="styles.css") as app:
101
  gr.Markdown("## 🎬 Movie Database Viewer 🎬")
102
+
103
+ with gr.Row():
104
+ # Profile selector and movie index with blank columns in between
105
+ movie_index_display = gr.Markdown("1/250", elem_id="movie-index")
106
+
107
+ # Adding two blank columns
108
+ blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
109
+ blank_column_2 = gr.Column(scale=1, elem_id="blank-column-2")
110
+ blank_column_3 = gr.Column(scale=1, elem_id="blank-column-3")
111
+
112
+ profile_selector = gr.Dropdown(
113
+ choices=['moiz', 'udisha', 'musab'],
114
+ value='moiz',
115
+ label="Profile",
116
+ interactive=True
117
+ )
118
+
119
  with gr.Row():
120
  with gr.Column(scale=1):
121
  poster = gr.Markdown("πŸŽ₯ Movie Poster Placeholder πŸŽ₯", elem_id="poster")
122
  with gr.Column(scale=2):
123
+ title = gr.Markdown("Title Placeholder", elem_id="title")
124
  ratings = gr.HTML("<div style='text-align: center;'>Ratings Placeholder</div>", elem_id="ratings")
125
  movie_details = gr.Markdown("Details will appear here.", elem_id="details")
126
+ user_rating = gr.Markdown("Your Rating: 0", elem_id="current-rating")
127
+
128
+ with gr.Row():
129
+ # Slider in its own row
130
+ rating_slider = gr.Slider(0, 10, step=0.25, label="Rate this movie:", elem_id="rating-slider", interactive=True, scale=2)
131
+
132
+ with gr.Row():
133
+
134
+ not_watched_button = gr.Button("🚫 Not Watched")
135
+
136
+ blank_column_1 = gr.Column(scale=1, elem_id="blank-column-1")
137
+
138
+
139
+ submit_button = gr.Button("βœ… Submit Rating")
140
 
141
  with gr.Row():
142
+ # Two blank columns between previous and next buttons
143
+ prev_button = gr.Button("⬅️ Previous", scale=1)
144
+
145
+ blank_column_1 = gr.Column(scale=2, elem_id="blank-column-1")
146
+ blank_column_2 = gr.Column(scale=2, elem_id="blank-column-2")
147
+
148
+ next_button = gr.Button("Next ➑️", scale=1)
149
 
150
  # Interactivity for buttons
151
+ profile_selector.change(
152
+ display_movie,
153
+ inputs=[gr.Text(value="stay", visible=False), profile_selector],
154
+ outputs=[title, poster, ratings, movie_details, user_rating, movie_index_display]
155
+ )
156
+
157
  prev_button.click(
158
  display_movie,
159
+ inputs=[gr.Text(value="prev", visible=False), profile_selector],
160
+ outputs=[title, poster, ratings, movie_details, user_rating, movie_index_display]
161
  )
162
  next_button.click(
163
  display_movie,
164
+ inputs=[gr.Text(value="next", visible=False), profile_selector],
165
+ outputs=[title, poster, ratings, movie_details, user_rating, movie_index_display]
166
+ )
167
+
168
+ submit_button.click(
169
+ submit_rating,
170
+ inputs=rating_slider,
171
+ outputs=[title, poster, ratings, movie_details, user_rating, movie_index_display]
172
+ )
173
+
174
+ not_watched_button.click(
175
+ not_watched,
176
+ outputs=[title, poster, ratings, movie_details, user_rating, movie_index_display]
177
  )
178
 
 
179
  app.launch()
styles.css CHANGED
@@ -1,4 +1,27 @@
1
- #custom-slider .gr-slider {
2
- width: 200px; /* Adjust the width to your preference */
3
- margin: 0 auto; /* Center the slider */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
 
1
+ .index-display {
2
+ font-size: 18px;
3
+ color: white;
4
+ text-align: right;
5
+ }
6
+
7
+ .button-container .gr-button {
8
+ height: 250px;
9
+ }
10
+
11
+ .slider-container {
12
+ display: flex;
13
+ align-items: center;
14
+ gap: 10px;
15
+ }
16
+
17
+ .slider-container .gr-slider {
18
+ flex: 1;
19
+ }
20
+
21
+ .gr-dropdown {
22
+ width: 100px;
23
+ }
24
+
25
+ .blank-column {
26
+ flex: 1;
27
  }