-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
70 lines (54 loc) · 2.33 KB
/
app.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import streamlit as st
from movieRecommenderSystem.app_exception.exception_handler import AppException
from movieRecommenderSystem.logging import logger
from movieRecommenderSystem.constants import *
from movieRecommenderSystem.config.configuration import ConfigurationManager
from movieRecommenderSystem.pipeline.inference import MovieRecommender
from main import TrainingPipeline
class App(object):
def __init__(self, config=ConfigurationManager()):
self.recommender = MovieRecommender()
self.movies = self.recommender.get_movies()
def train_engine(self):
try:
obj = TrainingPipeline()
obj.start_training_pipeline()
st.text("Training Completed!")
logger.info(f"Training completed successfully!")
except Exception as e:
raise AppException(e, sys) from e
def recommendation_engine(self, selected_movie):
try:
recommended_movies_titles, recommended_movies_posters = self.recommender.get_recommendations(selected_movie)
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
st.text(recommended_movies_titles[0])
st.image(recommended_movies_posters[0])
with col2:
st.text(recommended_movies_titles[1])
st.image(recommended_movies_posters[1])
with col3:
st.text(recommended_movies_titles[2])
st.image(recommended_movies_posters[2])
with col4:
st.text(recommended_movies_titles[3])
st.image(recommended_movies_posters[3])
with col5:
st.text(recommended_movies_titles[4])
st.image(recommended_movies_posters[4])
except Exception as e:
raise AppException(e, sys) from e
if __name__ == '__main__':
st.header("Movie Recommendation System using Machine Learning")
st.text("This is a content based recommendation system!")
app = App()
movie_list = app.movies['title'].values
selected_movie = st.selectbox(
'Type of select movies to get recommendations.',
movie_list
)
if st.button('Train Recommender System'):
app.train_engine()
if st.button('Show Recommendations'):
app.recommendation_engine(selected_movie)