Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -78
src/streamlit_app.py
CHANGED
|
@@ -240,64 +240,16 @@ if movie_id:
|
|
| 240 |
|
| 241 |
|
| 242 |
elif page:
|
| 243 |
-
st.title("Rate Random Movies")
|
| 244 |
-
|
| 245 |
-
all_genres = sorted(set(
|
| 246 |
-
genre.strip()
|
| 247 |
-
for sublist in movie_df["genres"].dropna().str.split("|")
|
| 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 |
-
|
| 285 |
-
|
| 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 |
-
|
| 294 |
-
movie = movie_pool.iloc[index]
|
| 295 |
poster_url, tmdb_link = get_tmdb_data(movie["clean_title"], movie["year"])
|
| 296 |
|
| 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)
|
| 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;'>
|
|
@@ -312,17 +264,9 @@ elif page:
|
|
| 312 |
if tmdb_link:
|
| 313 |
st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
|
| 314 |
|
| 315 |
-
|
| 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],
|
| 322 |
-
horizontal=True,
|
| 323 |
-
key=rating_key,
|
| 324 |
-
index=[1, 2, 3, 4, 5].index(default_rating)
|
| 325 |
-
)
|
| 326 |
|
| 327 |
col_submit, col_skip = st.columns([1, 1])
|
| 328 |
with col_submit:
|
|
@@ -332,12 +276,10 @@ elif page:
|
|
| 332 |
"rating": rating,
|
| 333 |
"timestamp": datetime.now().isoformat()
|
| 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:
|
|
@@ -450,7 +392,7 @@ else:
|
|
| 450 |
# Modell-Auswahl Dropdown
|
| 451 |
model_choice = st.radio(
|
| 452 |
"Choose Recommendation Model:",
|
| 453 |
-
options=["
|
| 454 |
index=0,
|
| 455 |
horizontal=True,
|
| 456 |
key="model_selection"
|
|
@@ -523,6 +465,7 @@ else:
|
|
| 523 |
}
|
| 524 |
.styled-table th, .styled-table td {
|
| 525 |
padding: 12px 15px;
|
|
|
|
| 526 |
}
|
| 527 |
.styled-table tbody tr {
|
| 528 |
border-bottom: 1px solid #333;
|
|
@@ -550,19 +493,6 @@ else:
|
|
| 550 |
|
| 551 |
user_ratings_dict = {r["movie_id"]: r["rating"] for r in all_ratings_data}
|
| 552 |
|
| 553 |
-
#if user_ratings_dict:
|
| 554 |
-
# if st.session_state["model_selection"] == "Neural Network":
|
| 555 |
-
# available_movies = movie_df["movieId"].tolist()
|
| 556 |
-
# recommendations = recommend_with_nn(user_ratings_dict, nn_model, encodings, top_n=10)
|
| 557 |
-
|
| 558 |
-
# else:
|
| 559 |
-
# ratings_full = pd.DataFrame(all_ratings_data)
|
| 560 |
-
# ratings_full["userId"] = 999999 # Dummy user
|
| 561 |
-
# ratings_full["rating"] = ratings_full["rating"].astype(float)
|
| 562 |
-
# recommendations = recommend_with_svd(svd_model, trainset, ratings_full, user_ratings_dict, top_n=10)
|
| 563 |
-
|
| 564 |
-
# recommended_df = pd.merge(recommendations, movie_df, on="movieId", how="left")
|
| 565 |
-
|
| 566 |
import random
|
| 567 |
|
| 568 |
if user_ratings_dict:
|
|
|
|
| 240 |
|
| 241 |
|
| 242 |
elif page:
|
| 243 |
+
st.title("🎬 Rate Random Movies")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
+
# Zufälligen Film ziehen
|
| 246 |
+
movie = movie_df.sample(1).iloc[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
poster_url, tmdb_link = get_tmdb_data(movie["clean_title"], movie["year"])
|
| 248 |
|
| 249 |
col1, col2 = st.columns([1, 2])
|
| 250 |
with col1:
|
| 251 |
if poster_url and "placeholder.com" not in poster_url:
|
| 252 |
+
st.image(poster_url, width=200)
|
| 253 |
else:
|
| 254 |
st.markdown("""
|
| 255 |
<div style='width:200px;height:300px;border:2px dashed gray;display:flex;align-items:center;justify-content:center;color:gray;font-size:12px;'>
|
|
|
|
| 264 |
if tmdb_link:
|
| 265 |
st.markdown(f"<a href='{tmdb_link}' target='_blank'>View on TMDb</a>", unsafe_allow_html=True)
|
| 266 |
|
| 267 |
+
# Bewertung
|
|
|
|
|
|
|
| 268 |
rating_key = f"rating_{movie['movieId']}"
|
| 269 |
+
rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, key=rating_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
col_submit, col_skip = st.columns([1, 1])
|
| 272 |
with col_submit:
|
|
|
|
| 276 |
"rating": rating,
|
| 277 |
"timestamp": datetime.now().isoformat()
|
| 278 |
})
|
|
|
|
| 279 |
st.rerun()
|
| 280 |
|
| 281 |
with col_skip:
|
| 282 |
if st.button("Didn't Watch", key=f"skip_{movie['movieId']}"):
|
|
|
|
| 283 |
st.rerun()
|
| 284 |
|
| 285 |
elif search_query:
|
|
|
|
| 392 |
# Modell-Auswahl Dropdown
|
| 393 |
model_choice = st.radio(
|
| 394 |
"Choose Recommendation Model:",
|
| 395 |
+
options=["SVD"],
|
| 396 |
index=0,
|
| 397 |
horizontal=True,
|
| 398 |
key="model_selection"
|
|
|
|
| 465 |
}
|
| 466 |
.styled-table th, .styled-table td {
|
| 467 |
padding: 12px 15px;
|
| 468 |
+
text-align: left;
|
| 469 |
}
|
| 470 |
.styled-table tbody tr {
|
| 471 |
border-bottom: 1px solid #333;
|
|
|
|
| 493 |
|
| 494 |
user_ratings_dict = {r["movie_id"]: r["rating"] for r in all_ratings_data}
|
| 495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
import random
|
| 497 |
|
| 498 |
if user_ratings_dict:
|