Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +16 -11
src/streamlit_app.py
CHANGED
|
@@ -250,20 +250,21 @@ elif page:
|
|
| 250 |
))
|
| 251 |
selected_genres = st.multiselect("Select genres:", options=all_genres, placeholder="Choose a genre")
|
| 252 |
|
| 253 |
-
#
|
| 254 |
if "rating_mode_state" not in st.session_state:
|
| 255 |
st.session_state.rating_mode_state = {
|
| 256 |
"movie_pool": [],
|
| 257 |
"index": 0,
|
| 258 |
-
"genre_filter": []
|
|
|
|
| 259 |
}
|
| 260 |
|
| 261 |
-
#
|
| 262 |
-
if st.session_state.rating_mode_state["
|
| 263 |
genre_filter = movie_df["genres"].apply(
|
| 264 |
lambda g: any(genre in g.split("|") for genre in selected_genres)
|
| 265 |
) if selected_genres else pd.Series([True] * len(movie_df))
|
| 266 |
-
|
| 267 |
filtered_df = movie_df[genre_filter].copy()
|
| 268 |
|
| 269 |
if filtered_df.empty:
|
|
@@ -271,17 +272,22 @@ elif page:
|
|
| 271 |
st.stop()
|
| 272 |
|
| 273 |
st.session_state.rating_mode_state = {
|
| 274 |
-
"movie_pool": filtered_df.sample(frac=1).reset_index(drop=True),
|
| 275 |
"index": 0,
|
| 276 |
-
"genre_filter": selected_genres
|
|
|
|
| 277 |
}
|
| 278 |
|
| 279 |
# Hole aktuellen Film
|
| 280 |
movie_pool = st.session_state.rating_mode_state["movie_pool"]
|
| 281 |
index = st.session_state.rating_mode_state["index"]
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
if index >= len(movie_pool):
|
| 284 |
-
st.
|
| 285 |
st.stop()
|
| 286 |
|
| 287 |
movie = movie_pool.iloc[index]
|
|
@@ -310,11 +316,10 @@ elif page:
|
|
| 310 |
st.markdown(f"### Movie {index + 1} of {len(movie_pool)}")
|
| 311 |
rating_key = f"rating_{movie['movieId']}_{index}"
|
| 312 |
rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, key=rating_key)
|
| 313 |
-
|
| 314 |
col_submit, col_skip = st.columns([1, 1])
|
| 315 |
with col_submit:
|
| 316 |
if st.button("Submit Rating", key=f"submit_{movie['movieId']}_{index}") and rating:
|
| 317 |
-
|
| 318 |
save_rating_to_json({
|
| 319 |
"movie_id": int(movie["movieId"]),
|
| 320 |
"rating": rating,
|
|
@@ -324,7 +329,7 @@ elif page:
|
|
| 324 |
st.rerun()
|
| 325 |
|
| 326 |
with col_skip:
|
| 327 |
-
if st.button("Didn't Watch"):
|
| 328 |
st.session_state.rating_mode_state["index"] += 1
|
| 329 |
st.rerun()
|
| 330 |
|
|
|
|
| 250 |
))
|
| 251 |
selected_genres = st.multiselect("Select genres:", options=all_genres, placeholder="Choose a genre")
|
| 252 |
|
| 253 |
+
# Initialzustand setzen
|
| 254 |
if "rating_mode_state" not in st.session_state:
|
| 255 |
st.session_state.rating_mode_state = {
|
| 256 |
"movie_pool": [],
|
| 257 |
"index": 0,
|
| 258 |
+
"genre_filter": [],
|
| 259 |
+
"initialized": False
|
| 260 |
}
|
| 261 |
|
| 262 |
+
# Neuinitialisierung per Button starten
|
| 263 |
+
if st.button("Start Rating Session") or not st.session_state.rating_mode_state["initialized"]:
|
| 264 |
genre_filter = movie_df["genres"].apply(
|
| 265 |
lambda g: any(genre in g.split("|") for genre in selected_genres)
|
| 266 |
) if selected_genres else pd.Series([True] * len(movie_df))
|
| 267 |
+
|
| 268 |
filtered_df = movie_df[genre_filter].copy()
|
| 269 |
|
| 270 |
if filtered_df.empty:
|
|
|
|
| 272 |
st.stop()
|
| 273 |
|
| 274 |
st.session_state.rating_mode_state = {
|
| 275 |
+
"movie_pool": filtered_df.sample(frac=1, random_state=42).reset_index(drop=True),
|
| 276 |
"index": 0,
|
| 277 |
+
"genre_filter": selected_genres,
|
| 278 |
+
"initialized": True
|
| 279 |
}
|
| 280 |
|
| 281 |
# Hole aktuellen Film
|
| 282 |
movie_pool = st.session_state.rating_mode_state["movie_pool"]
|
| 283 |
index = st.session_state.rating_mode_state["index"]
|
| 284 |
|
| 285 |
+
if not movie_pool:
|
| 286 |
+
st.info("Please start a rating session.")
|
| 287 |
+
st.stop()
|
| 288 |
+
|
| 289 |
if index >= len(movie_pool):
|
| 290 |
+
st.success("✅ You've rated all movies in this session.")
|
| 291 |
st.stop()
|
| 292 |
|
| 293 |
movie = movie_pool.iloc[index]
|
|
|
|
| 316 |
st.markdown(f"### Movie {index + 1} of {len(movie_pool)}")
|
| 317 |
rating_key = f"rating_{movie['movieId']}_{index}"
|
| 318 |
rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, key=rating_key)
|
| 319 |
+
|
| 320 |
col_submit, col_skip = st.columns([1, 1])
|
| 321 |
with col_submit:
|
| 322 |
if st.button("Submit Rating", key=f"submit_{movie['movieId']}_{index}") and rating:
|
|
|
|
| 323 |
save_rating_to_json({
|
| 324 |
"movie_id": int(movie["movieId"]),
|
| 325 |
"rating": rating,
|
|
|
|
| 329 |
st.rerun()
|
| 330 |
|
| 331 |
with col_skip:
|
| 332 |
+
if st.button("Didn't Watch", key=f"skip_{movie['movieId']}_{index}"):
|
| 333 |
st.session_state.rating_mode_state["index"] += 1
|
| 334 |
st.rerun()
|
| 335 |
|