lenawilli commited on
Commit
7f97bdd
·
verified ·
1 Parent(s): 459f1e3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -7
src/streamlit_app.py CHANGED
@@ -189,18 +189,22 @@ if movie_id:
189
 
190
  rating_key = f"detail_rating_{movie_id}"
191
  user_rating = next((r["rating"] for r in all_ratings_data if r["movie_id"] == movie_id), None)
192
- if user_rating:
193
- st.markdown(f"**Your Rating:** {render_star_rating(user_rating)}", unsafe_allow_html=True)
194
- else:
195
- st.markdown("### Rate this movie")
196
- new_rating = st.radio("Your Rating:", [1, 2, 3, 4, 5], horizontal=True, key=rating_key)
197
- if st.button("Submit Rating") and st.session_state[rating_key]:
 
 
198
  save_rating_to_json({
199
  "movie_id": movie_id,
200
- "rating": st.session_state[rating_key],
201
  "timestamp": datetime.now().isoformat()
202
  })
 
203
  st.rerun()
 
204
  except Exception as e:
205
  st.error("Could not load movie details.")
206
 
 
189
 
190
  rating_key = f"detail_rating_{movie_id}"
191
  user_rating = next((r["rating"] for r in all_ratings_data if r["movie_id"] == movie_id), None)
192
+ st.markdown("### Your Rating")
193
+ existing_rating = next((r["rating"] for r in all_ratings_data if r["movie_id"] == movie_id), None)
194
+ initial_index = existing_rating - 1 if existing_rating else None
195
+
196
+ new_rating = st.radio("Rate this movie:", [1, 2, 3, 4, 5], horizontal=True, index=initial_index, key=rating_key)
197
+
198
+ if st.button("Submit Rating"):
199
+ if new_rating:
200
  save_rating_to_json({
201
  "movie_id": movie_id,
202
+ "rating": new_rating,
203
  "timestamp": datetime.now().isoformat()
204
  })
205
+ st.success("Rating saved.")
206
  st.rerun()
207
+
208
  except Exception as e:
209
  st.error("Could not load movie details.")
210