gaspar-avit commited on
Commit
f7716a6
1 Parent(s): 7414166

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -122,18 +122,6 @@ def authenticate_kaggle():
122
  api.authenticate()
123
 
124
 
125
- def map_year(x):
126
- a = ''
127
- if isinstance(x, str):
128
- try:
129
- a = re.search('\(([0-9_]+)\)', x[-7:]).group(1)
130
- except:
131
- a = ''
132
- else:
133
- a = ''
134
- return a
135
-
136
-
137
  @st.experimental_memo(persist=True, show_spinner=False, suppress_st_warning=True, max_entries=1)
138
  def load_dataset():
139
  """
@@ -155,17 +143,17 @@ def load_dataset():
155
  ## ----------------------------- ##
156
 
157
  # Downloading Movies dataset
158
- api.dataset_download_file('garymk/movielens-25m-dataset', 'ml-25m/movies.csv')
159
 
160
  # Extract data
161
- zf = ZipFile('movies.csv.zip')
162
  zf.extractall()
163
  zf.close()
164
 
165
  # Create dataframe
166
- data = pd.read_csv('movies.csv', low_memory=False)
167
- #data['year'] = data['release_date'].map(lambda x: x.split('-')[0] if isinstance(x, str) else '0')
168
- data['year'] = data['title'].map(map_year)
169
 
170
  return data
171
 
@@ -223,7 +211,9 @@ def generate_poster(movie_data):
223
  """
224
 
225
  # Get movie metadata
226
- genres_string = movie_data['genres'].values[0].replace('|', ', ')
 
 
227
  year = movie_data['year'].values[0]
228
 
229
 
@@ -304,7 +294,7 @@ if __name__ == "__main__":
304
  st.text("")
305
 
306
  ## Select box with all the movies as choices
307
- session.selected_movie = st.selectbox(label="Select a movie to generate alternative poster", options=data.title)
308
 
309
  st.text("")
310
  st.text("")
@@ -315,7 +305,7 @@ if __name__ == "__main__":
315
 
316
  ## Generate poster
317
  if is_clicked:
318
- poster = generate_poster(data[data.title==session.selected_movie])
319
  #generate_poster.clear()
320
  #st.runtime.legacy_caching.clear_cache()
321
 
@@ -331,6 +321,6 @@ if __name__ == "__main__":
331
  is_clicked_rerun = col1.button(label="Rerun with same movie!")
332
 
333
  if is_clicked_rerun:
334
- poster = generate_poster(data[data.title==selected_movie])
335
  """
336
 
 
122
  api.authenticate()
123
 
124
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  @st.experimental_memo(persist=True, show_spinner=False, suppress_st_warning=True, max_entries=1)
126
  def load_dataset():
127
  """
 
143
  ## ----------------------------- ##
144
 
145
  # Downloading Movies dataset
146
+ api.dataset_download_file('rounakbanik/the-movies-dataset', 'movies_metadata.csv')
147
 
148
  # Extract data
149
+ zf = ZipFile('movies_metadata.csv.zip')
150
  zf.extractall()
151
  zf.close()
152
 
153
  # Create dataframe
154
+ data = pd.read_csv('movies_metadata.csv', low_memory=False)
155
+ data['year'] = data["release_date"].map(lambda x: x.split('-')[0] if isinstance(x, str) else '0')
156
+ data['title_year'] = data['title'] + ' (' + data['year'] + ')'
157
 
158
  return data
159
 
 
211
  """
212
 
213
  # Get movie metadata
214
+ genres = [i['name'] for i in eval(movie_data['genres'].values[0])]
215
+ genres_string = ', '.join(genres)
216
+
217
  year = movie_data['year'].values[0]
218
 
219
 
 
294
  st.text("")
295
 
296
  ## Select box with all the movies as choices
297
+ session.selected_movie = st.selectbox(label="Select a movie to generate alternative poster", options=data.title_year)
298
 
299
  st.text("")
300
  st.text("")
 
305
 
306
  ## Generate poster
307
  if is_clicked:
308
+ poster = generate_poster(data[data.title_year==session.selected_movie])
309
  #generate_poster.clear()
310
  #st.runtime.legacy_caching.clear_cache()
311
 
 
321
  is_clicked_rerun = col1.button(label="Rerun with same movie!")
322
 
323
  if is_clicked_rerun:
324
+ poster = generate_poster(data[data.title_year==selected_movie])
325
  """
326