shajmaan commited on
Commit
5c6823a
1 Parent(s): 57d15d0

Upload app.py

Browse files

check this ccode

Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sklearn.feature_extraction.text import TfidfVectorizer
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+
6
+ df = pd.read_csv("movies.csv")
7
+ features = ["keywords", "cast", "genres", "director"]
8
+
9
+ for feature in features:
10
+ df[feature] = df[feature].fillna('')
11
+
12
+ def combined_features(row):
13
+ return row['keywords']+" "+row['cast']+" "+row['genres']+" "+row['director']
14
+
15
+ df["combined_features"] = df.apply(combined_features, axis=1)
16
+
17
+ Tfidf_vect = TfidfVectorizer()
18
+ vector_matrix = Tfidf_vect.fit_transform(df["combined_features"])
19
+ vector_matrix.toarray()
20
+
21
+ cosine_sim = cosine_similarity(vector_matrix)
22
+
23
+ def get_index_from_title(title):
24
+ return df[df.title == title]["index"].values[0]
25
+
26
+ def get_title_from_index(index):
27
+ return df[df.index == index]["title"].values[0]
28
+
29
+ def check_movie(m_name):
30
+ movie_index = get_index_from_title(m_name)
31
+ similar_movies= list(enumerate(cosine_sim[movie_index]))
32
+ sorted_similar_movies = sorted(similar_movies, key=lambda x:x[1], reverse=True)
33
+ mv = get_suggestions(sorted_similar_movies)
34
+ return mv
35
+
36
+ def get_suggestions(sorted_similar_movies):
37
+ i=0
38
+ movies = ""
39
+ for movie in sorted_similar_movies:
40
+ t = get_title_from_index(movie[0])
41
+ movies = movies + t +"\n"
42
+
43
+ i=i+1
44
+ if i>10:
45
+ print(movies)
46
+ return movies
47
+
48
+ def check(enter_movie_name):
49
+ mvs = check_movie(enter_movie_name)
50
+ return mvs
51
+
52
+
53
+ movie = gr.Interface(fn=check, inputs="text", outputs="text")
54
+ movie.launch(share=True)