lenawilli commited on
Commit
0aa3728
·
verified ·
1 Parent(s): 94d8b8c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +49 -47
src/streamlit_app.py CHANGED
@@ -208,6 +208,8 @@ if movie_id:
208
  No picture available
209
  </div>
210
  """, unsafe_allow_html=True)
 
 
211
 
212
  with col2:
213
  st.subheader("Details")
@@ -231,8 +233,54 @@ if movie_id:
231
  })
232
 
233
  st.success("Rating saved.")
234
- st.rerun()
 
 
 
 
 
 
 
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  elif search_query:
237
  st.title(f"Search Results for '{search_query}'")
238
 
@@ -337,52 +385,6 @@ elif search_query:
337
  </div>
338
  """, unsafe_allow_html=True)
339
 
340
- elif page:
341
- st.title("Rate Random Movies")
342
-
343
- movie = movie_df.sample(1).iloc[0]
344
- poster_url, tmdb_link = get_tmdb_data(movie["clean_title"], movie["year"])
345
- movie_id = int(movie["movieId"]) # explizit casten!
346
-
347
- col1, col2 = st.columns([1, 2])
348
-
349
- with col1:
350
- if poster_url and "placeholder.com" not in poster_url:
351
- st.image(poster_url, width=200)
352
- else:
353
- st.markdown("""
354
- <div style='width:200px;height:300px;border:2px dashed gray;display:flex;align-items:center;justify-content:center;color:gray;font-size:12px;'>
355
- No<br>Image
356
- </div>
357
- """, unsafe_allow_html=True)
358
-
359
- with col2:
360
- st.subheader(movie["clean_title"])
361
- st.markdown(f"**Genres:** {movie['genres']}")
362
- st.markdown(f"**Year:** {movie['year']}")
363
- if tmdb_link:
364
- st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
365
-
366
- # Bewertungsauswahl
367
- rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, key=f"rating_{movie_id}")
368
-
369
- # Zwei Buttons in zwei Spalten – ganz ohne Form
370
- col_submit, col_skip = st.columns([1, 1])
371
-
372
- with col_submit:
373
- if st.button("Submit Rating", key=f"submit_{movie_id}"):
374
- save_rating_to_json({
375
- "movie_id": movie_id,
376
- "rating": rating,
377
- "timestamp": datetime.now().isoformat()
378
- })
379
- st.success("Rating saved.")
380
- st.rerun()
381
-
382
- with col_skip:
383
- if st.button("Didn't Watch", key=f"skip_{movie_id}"):
384
- st.rerun()
385
-
386
  else:
387
  st.title("Welcome to Movie Recommender")
388
 
 
208
  No picture available
209
  </div>
210
  """, unsafe_allow_html=True)
211
+ except Exception as e:
212
+ st.error(f"Could not load movie details: {e}")
213
 
214
  with col2:
215
  st.subheader("Details")
 
233
  })
234
 
235
  st.success("Rating saved.")
236
+ st.rerun()
237
+
238
+ elif page:
239
+ st.title("Rate Random Movies")
240
+
241
+ movie = movie_df.sample(1).iloc[0]
242
+ poster_url, tmdb_link = get_tmdb_data(movie["clean_title"], movie["year"])
243
+ movie_id = int(movie["movieId"]) # explizit casten!
244
 
245
+ col1, col2 = st.columns([1, 2])
246
+
247
+ with col1:
248
+ if poster_url and "placeholder.com" not in poster_url:
249
+ st.image(poster_url, width=200)
250
+ else:
251
+ st.markdown("""
252
+ <div style='width:200px;height:300px;border:2px dashed gray;display:flex;align-items:center;justify-content:center;color:gray;font-size:12px;'>
253
+ No<br>Image
254
+ </div>
255
+ """, unsafe_allow_html=True)
256
+
257
+ with col2:
258
+ st.subheader(movie["clean_title"])
259
+ st.markdown(f"**Genres:** {movie['genres']}")
260
+ st.markdown(f"**Year:** {movie['year']}")
261
+ if tmdb_link:
262
+ st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
263
+
264
+ # Bewertungsauswahl
265
+ rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, key=f"rating_{movie_id}")
266
+
267
+ # Zwei Buttons in zwei Spalten – ganz ohne Form
268
+ col_submit, col_skip = st.columns([1, 1])
269
+
270
+ with col_submit:
271
+ if st.button("Submit Rating", key=f"submit_{movie_id}"):
272
+ save_rating_to_json({
273
+ "movie_id": movie_id,
274
+ "rating": rating,
275
+ "timestamp": datetime.now().isoformat()
276
+ })
277
+ st.success("Rating saved.")
278
+ st.rerun()
279
+
280
+ with col_skip:
281
+ if st.button("Didn't Watch", key=f"skip_{movie_id}"):
282
+ st.rerun()
283
+
284
  elif search_query:
285
  st.title(f"Search Results for '{search_query}'")
286
 
 
385
  </div>
386
  """, unsafe_allow_html=True)
387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  else:
389
  st.title("Welcome to Movie Recommender")
390