CoolFace
Apppublic

InHUMAN/Game-Recommendation-System

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py49 linesDownload Raw Back to root
1import streamlit as st2import pickle3import pandas  as pd4from PIL import Image5import requests6from bs4 import BeautifulSoup7 8st.title('Game Recommendation System')9 10game_list=pickle.load(open('games.pkl','rb'))11similarity_list=pickle.load(open('similarities.pkl','rb'))12games=pd.DataFrame(game_list)13 14def game_recommender(game):15    game_index=games[games['name']==game].index[0]16    distances=sorted(list(enumerate(similarity_list[game_index])),reverse=True, key=lambda x:x[1])[1:10]17    game_recs=[]18    for i in distances:19        game_recs.append(games.iloc[i[0]]['name'])20    return game_recs21    22 23game_selected=st.selectbox('',(games['name']))24 25 26if st.button('Recommend'):27   28    game_recs=game_recommender(game_selected)29    for i in game_recs:30        word = f'latest {i} video game cover photo'31        url = 'https://www.google.com/search?q={0}&tbm=isch'.format(word)32        content = requests.get(url).content33        soup = BeautifulSoup(content,'lxml')34        images = soup.findAll('img')35        c=036        img_link=''37        for image in images:38            if c==1:39                img_link=image.get('src')40                break41            c+=142 43        im = Image.open(requests.get(img_link, stream=True).raw)44        st.header(i)45        st.image(im)46        47 48 49