Spaces:
Build error
Build error
| import pandas as pd | |
| import streamlit as st | |
| import requests | |
| from io import BytesIO | |
| from PIL import Image | |
| data_titles = pd.read_pickle("data/dict_of_all_titles.pkl") | |
| data_ids = pd.read_pickle("data/dict_of_all_ids.pkl") | |
| def ids_to_titles(ids_list): | |
| return [data_ids[title] for title in ids_list] | |
| def titles_to_ids(titles_list): | |
| return [data_titles[id] for id in titles_list] | |
| def generate_app_gamebox(titles): | |
| """ | |
| Placeholder | |
| """ | |
| titles_id = titles_to_ids(titles) | |
| for id in titles_id: | |
| url = f"https://cdn.cloudflare.steamstatic.com/steam/apps/{id}/header.jpg" | |
| resp = requests.get(url) | |
| if resp.status_code == 200: | |
| container = st.container() | |
| img_col, pref_col = container.columns([3, 2]) | |
| img_col.image(BytesIO(resp.content)) | |
| pref_col.selectbox( | |
| "Your rating:", | |
| options=["Positive", "Negative"], | |
| key=id, | |
| ) | |
| return titles_id | |
| def generate_res_gamebox(ids): | |
| """ | |
| Placeholder | |
| """ | |
| for id in ids: | |
| url_page = f"https://store.steampowered.com/app/{id}/" | |
| url_img = f"https://cdn.cloudflare.steamstatic.com/steam/apps/{id}/header.jpg" | |
| resp = requests.get(url_img) | |
| if resp.status_code == 200: | |
| with st.container(): | |
| st.image(BytesIO(resp.content)) | |
| # st.caption(data_ids[id]) | |
| st.caption(f"[{data_ids[id]}]({url_page})") | |
| st.divider() | |
| def combine_hybrid_result(res_ease, res_cbf): | |
| try: | |
| df = pd.concat([res_ease, res_cbf], axis=0) | |
| res_final = df.groupby("app_id").sum().sort_values( | |
| ["predicted_score"], ascending=False) | |
| # return res_final.head(10).index.tolist() | |
| return res_final | |
| except: | |
| st.error("Recommendation failed. Please select with at least 2 games title.") | |
| # for title in titles_list: | |
| # # url = f"https://store.steampowered.com/app/" | |
| # with st.container(): | |