Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +34 -45
src/streamlit_app.py
CHANGED
|
@@ -248,48 +248,46 @@ elif page:
|
|
| 248 |
for genre in sublist
|
| 249 |
))
|
| 250 |
|
| 251 |
-
selected_genres = st.multiselect(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
if "rating_mode_state" not in st.session_state:
|
| 254 |
st.session_state.rating_mode_state = {
|
| 255 |
"movie_pool": pd.DataFrame(),
|
| 256 |
-
"index": 0
|
| 257 |
-
"genre_filter": [],
|
| 258 |
-
"active": False
|
| 259 |
}
|
| 260 |
|
| 261 |
-
|
| 262 |
-
if not selected_genres:
|
| 263 |
-
st.warning("Please select at least one genre.")
|
| 264 |
-
st.stop()
|
| 265 |
-
|
| 266 |
-
genre_filter = movie_df["genres"].apply(
|
| 267 |
-
lambda g: any(genre in g.split("|") for genre in selected_genres)
|
| 268 |
-
)
|
| 269 |
-
filtered_df = movie_df[genre_filter].copy()
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
st.stop()
|
| 274 |
|
| 275 |
-
st.session_state.rating_mode_state["movie_pool"] = filtered_df.sample(frac=1, random_state=42).reset_index(drop=True)
|
| 276 |
-
st.session_state.rating_mode_state["index"] = 0
|
| 277 |
-
st.session_state.rating_mode_state["genre_filter"] = selected_genres
|
| 278 |
-
st.session_state.rating_mode_state["active"] = True
|
| 279 |
-
st.rerun()
|
| 280 |
-
|
| 281 |
-
mode = st.session_state.rating_mode_state
|
| 282 |
-
if not mode["active"]:
|
| 283 |
-
st.info("Please select genres and start a session.")
|
| 284 |
-
st.stop()
|
| 285 |
-
|
| 286 |
movie_pool = mode["movie_pool"]
|
| 287 |
index = mode["index"]
|
| 288 |
|
| 289 |
-
if
|
| 290 |
-
st.success("
|
| 291 |
-
if st.button("
|
| 292 |
-
mode["
|
| 293 |
st.rerun()
|
| 294 |
st.stop()
|
| 295 |
|
|
@@ -299,11 +297,11 @@ elif page:
|
|
| 299 |
col1, col2 = st.columns([1, 2])
|
| 300 |
with col1:
|
| 301 |
if poster_url and "placeholder.com" not in poster_url:
|
| 302 |
-
st.image(poster_url, width=
|
| 303 |
else:
|
| 304 |
st.markdown("""
|
| 305 |
-
<div style='width:300px;border:2px dashed gray;
|
| 306 |
-
No
|
| 307 |
</div>
|
| 308 |
""", unsafe_allow_html=True)
|
| 309 |
|
|
@@ -314,13 +312,10 @@ elif page:
|
|
| 314 |
if tmdb_link:
|
| 315 |
st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
|
| 316 |
|
| 317 |
-
st.markdown(f"### Movie {index + 1} of {len(movie_pool)}")
|
| 318 |
-
|
| 319 |
-
# Bestehende Bewertung laden
|
| 320 |
existing_rating = next((r["rating"] for r in all_ratings_data if r["movie_id"] == movie["movieId"]), None)
|
| 321 |
default_rating = existing_rating if existing_rating else 1
|
| 322 |
|
| 323 |
-
rating_key = f"rating_{movie['movieId']}
|
| 324 |
rating = st.radio(
|
| 325 |
"Rate this movie:",
|
| 326 |
options=[1, 2, 3, 4, 5],
|
|
@@ -331,7 +326,7 @@ elif page:
|
|
| 331 |
|
| 332 |
col_submit, col_skip = st.columns([1, 1])
|
| 333 |
with col_submit:
|
| 334 |
-
if st.button("Submit Rating", key=f"submit_{movie['movieId']}
|
| 335 |
save_rating_to_json({
|
| 336 |
"movie_id": int(movie["movieId"]),
|
| 337 |
"rating": rating,
|
|
@@ -339,17 +334,11 @@ elif page:
|
|
| 339 |
})
|
| 340 |
mode["index"] += 1
|
| 341 |
st.rerun()
|
| 342 |
-
st.stop()
|
| 343 |
|
| 344 |
with col_skip:
|
| 345 |
-
if st.button("Didn't Watch", key=f"skip_{movie['movieId']}
|
| 346 |
mode["index"] += 1
|
| 347 |
st.rerun()
|
| 348 |
-
st.stop()
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
|
| 354 |
elif search_query:
|
| 355 |
st.title(f"Search Results for '{search_query}'")
|
|
|
|
| 248 |
for genre in sublist
|
| 249 |
))
|
| 250 |
|
| 251 |
+
selected_genres = st.multiselect(
|
| 252 |
+
"Select genres:",
|
| 253 |
+
options=all_genres,
|
| 254 |
+
default=st.session_state.get("selected_genres", []),
|
| 255 |
+
placeholder="Choose a genre"
|
| 256 |
+
)
|
| 257 |
+
st.session_state["selected_genres"] = selected_genres
|
| 258 |
|
| 259 |
if "rating_mode_state" not in st.session_state:
|
| 260 |
st.session_state.rating_mode_state = {
|
| 261 |
"movie_pool": pd.DataFrame(),
|
| 262 |
+
"index": 0
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
|
| 265 |
+
mode = st.session_state.rating_mode_state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
+
if mode["movie_pool"].empty or mode.get("genre_filter") != selected_genres:
|
| 268 |
+
if selected_genres:
|
| 269 |
+
genre_filter = movie_df["genres"].apply(
|
| 270 |
+
lambda g: any(genre in g.split("|") for genre in selected_genres)
|
| 271 |
+
)
|
| 272 |
+
filtered_df = movie_df[genre_filter].copy()
|
| 273 |
+
if not filtered_df.empty:
|
| 274 |
+
mode["movie_pool"] = filtered_df.sample(frac=1, random_state=42).reset_index(drop=True)
|
| 275 |
+
mode["index"] = 0
|
| 276 |
+
mode["genre_filter"] = selected_genres
|
| 277 |
+
else:
|
| 278 |
+
st.warning("No movies found for selected genres.")
|
| 279 |
+
st.stop()
|
| 280 |
+
else:
|
| 281 |
+
st.info("Please select at least one genre.")
|
| 282 |
st.stop()
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
movie_pool = mode["movie_pool"]
|
| 285 |
index = mode["index"]
|
| 286 |
|
| 287 |
+
if index >= len(movie_pool):
|
| 288 |
+
st.success("You've gone through all movies in this selection.")
|
| 289 |
+
if st.button("Restart"):
|
| 290 |
+
mode["index"] = 0
|
| 291 |
st.rerun()
|
| 292 |
st.stop()
|
| 293 |
|
|
|
|
| 297 |
col1, col2 = st.columns([1, 2])
|
| 298 |
with col1:
|
| 299 |
if poster_url and "placeholder.com" not in poster_url:
|
| 300 |
+
st.image(poster_url, width=200) # Einheitlich kleine Breite
|
| 301 |
else:
|
| 302 |
st.markdown("""
|
| 303 |
+
<div style='width:200px;height:300px;border:2px dashed gray;display:flex;align-items:center;justify-content:center;color:gray;font-size:12px;'>
|
| 304 |
+
No<br>Image
|
| 305 |
</div>
|
| 306 |
""", unsafe_allow_html=True)
|
| 307 |
|
|
|
|
| 312 |
if tmdb_link:
|
| 313 |
st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
|
| 314 |
|
|
|
|
|
|
|
|
|
|
| 315 |
existing_rating = next((r["rating"] for r in all_ratings_data if r["movie_id"] == movie["movieId"]), None)
|
| 316 |
default_rating = existing_rating if existing_rating else 1
|
| 317 |
|
| 318 |
+
rating_key = f"rating_{movie['movieId']}"
|
| 319 |
rating = st.radio(
|
| 320 |
"Rate this movie:",
|
| 321 |
options=[1, 2, 3, 4, 5],
|
|
|
|
| 326 |
|
| 327 |
col_submit, col_skip = st.columns([1, 1])
|
| 328 |
with col_submit:
|
| 329 |
+
if st.button("Submit Rating", key=f"submit_{movie['movieId']}"):
|
| 330 |
save_rating_to_json({
|
| 331 |
"movie_id": int(movie["movieId"]),
|
| 332 |
"rating": rating,
|
|
|
|
| 334 |
})
|
| 335 |
mode["index"] += 1
|
| 336 |
st.rerun()
|
|
|
|
| 337 |
|
| 338 |
with col_skip:
|
| 339 |
+
if st.button("Didn't Watch", key=f"skip_{movie['movieId']}"):
|
| 340 |
mode["index"] += 1
|
| 341 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
elif search_query:
|
| 344 |
st.title(f"Search Results for '{search_query}'")
|