This is the reference solution for the AI110 Module 1 Tinker Playlist Chaos. It is the starter app with every planted bug fixed, so you can compare it against the version you debugged in the lab. It is not the only correct implementation — if your app behaves the way this one does, you're in good shape.
Starter repo:
ai110-module1tinker-playlistchaos-starter
pip install -r requirements.txt
streamlit run app.pyapp.py— the Streamlit UI (mood profile, add-song form, playlist tabs, search, lucky pick, stats, history). Unchanged from the starter; no bugs live here.playlist_logic.py— all classification, stats, search, and lucky-pick logic. All five fixes are here.
The starter had five bugs. Each one below matches the Intended Behavior Overview in the Tinker.
classify_song— priority + keyword case. Chill conditions are now checked before the Hype conditions, so a favorite-genre match can no longer drag a genuinely low-energy song into Hype. Chill keyword matching compares against the lowercased title, so"Lofi Rain"matches"lofi".compute_playlist_stats—hype_ratio. The ratio now divides by the total number of songs instead of by the Hype count (which made the ratio always1.0).compute_playlist_stats—avg_energy. Average energy now sums energy across all songs, not just the Hype list.search_songs— inverted substring check. The match is nowquery in value(e.g. searching"AC"finds"AC/DC"), not the backwardsvalue in query.random_choice_or_none— empty list. ReturnsNoneon an empty list instead of raisingIndexError, keeping Lucky Pick safe when a playlist is empty.
Add an ambient, low-energy song and confirm it lands in Chill. Add several low-energy songs and confirm Average Energy and Hype Ratio reflect the whole library. Search a partial artist string. Run Lucky Pick on an empty playlist. All four should behave sensibly — no wrong buckets, no stuck ratios, no crashes.