File size: 1,290 Bytes
4cc4ecf
 
 
 
 
f7e2c94
4cc4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
import pickle
import pandas  as pd
from PIL import Image
import requests
from bs4 import BeautifulSoup

st.title('Game Recommendation System')

game_list=pickle.load(open('games.pkl','rb'))
similarity_list=pickle.load(open('similarities.pkl','rb'))
games=pd.DataFrame(game_list)

def game_recommender(game):
    game_index=games[games['name']==game].index[0]
    distances=sorted(list(enumerate(similarity_list[game_index])),reverse=True, key=lambda x:x[1])[1:10]
    game_recs=[]
    for i in distances:
        game_recs.append(games.iloc[i[0]]['name'])
    return game_recs
    

game_selected=st.selectbox('',(games['name']))


if st.button('Recommend'):
   
    game_recs=game_recommender(game_selected)
    for i in game_recs:
        word = f'latest {i} video game cover photo'
        url = 'https://www.google.com/search?q={0}&tbm=isch'.format(word)
        content = requests.get(url).content
        soup = BeautifulSoup(content,'lxml')
        images = soup.findAll('img')
        c=0
        img_link=''
        for image in images:
            if c==1:
                img_link=image.get('src')
                break
            c+=1

        im = Image.open(requests.get(img_link, stream=True).raw)
        st.header(i)
        st.image(im)