mr-robber commited on
Commit
dc37957
1 Parent(s): 2e80467

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +176 -6
app.py CHANGED
@@ -3,10 +3,180 @@ from bs4 import BeautifulSoup
3
  import requests
4
  import re
5
  import pandas as pd
6
- def sketch_recognition(text):
7
- url = 'http://www.imdb.com/chart/top'
8
- response = requests.get(url)
9
- soup = BeautifulSoup(response.text, "html.parser")
10
- return response
11
 
12
- gr.Interface(fn=sketch_recognition, inputs="text", outputs="text").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import requests
4
  import re
5
  import pandas as pd
 
 
 
 
 
6
 
7
+
8
+ def get_video_address(row):
9
+
10
+ inner = []
11
+ for dictionary in row:
12
+ type = dictionary.get('type')
13
+ if(type == 'Trailer'):
14
+ inner.append(dictionary['key'])
15
+ return inner
16
+
17
+
18
+ css_code='''
19
+
20
+ .bdy{
21
+ color: #eee7d8;
22
+ margin: 0 0 60px 0;
23
+ font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
24
+ }
25
+ .contents{
26
+ display: flex;
27
+ align-content: space-around;
28
+ justify-content: center;
29
+ }
30
+
31
+ .img {
32
+ display: block;
33
+ width: calc(34% - 0.125rem);
34
+ height:auto;
35
+ }
36
+
37
+ .video{
38
+ width: calc(66% - 0.125rem);
39
+ height:auto;
40
+ margin-left: 0.25rem;
41
+
42
+ }
43
+
44
+ .center {
45
+ border: 3px solid green;
46
+ }
47
+
48
+ .top{
49
+ display: flex;
50
+ justify-content: space-between;
51
+ margin:0;
52
+
53
+
54
+ }
55
+
56
+ .inline{
57
+ display: flex;
58
+ margin:0;
59
+ }
60
+ .time{
61
+ padding: 0 0 0 15px;
62
+ }
63
+
64
+ .topleft{
65
+ padding: 0px;
66
+ margin: 0px;
67
+ line-height: 0;
68
+
69
+ }
70
+
71
+ .topright{
72
+ line-height: 0;
73
+ margin:0;
74
+ padding:0;
75
+
76
+ }
77
+
78
+ .name{
79
+ margin: 20px 0 5px 0;
80
+ }
81
+ '''
82
+
83
+
84
+ def combine(x):
85
+ lst = []
86
+ if isinstance(x, list) == True:
87
+ for i in x:
88
+ lst.append(i['name'])
89
+ return '|'.join(lst)
90
+ else:
91
+ np.nan
92
+
93
+
94
+ import requests
95
+ headers = {
96
+ "accept": "application/json",
97
+ "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJmMTNkMmNiMTY4MWM3ZWEyMjNiYjgxZTUyYmMzMDUyMCIsInN1YiI6IjY0YTY5MTU1YzNiZmZlMDBjODZiYzRlZSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.H6zk_gSiudNdZTsgwYHFQnJiVXfR_BX5DfYNIoIsRv8"
98
+ }
99
+
100
+
101
+ import requests
102
+ def recommend_movie(movie_name, Number_of_Recommendation):
103
+ Number_of_Recommendation = int(Number_of_Recommendation)
104
+ outputIds = ['tt0114709', 'tt0113497', 'tt0113228', 'tt0114885', 'tt0113041']
105
+ html = '''
106
+ <html>
107
+ <head>
108
+ <link rel="stylesheet" href="styles.css" />
109
+ </head>
110
+ <body>
111
+ '''
112
+ headers = {
113
+ "accept": "application/json",
114
+ "Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJmMTNkMmNiMTY4MWM3ZWEyMjNiYjgxZTUyYmMzMDUyMCIsInN1YiI6IjY0YTY5MTU1YzNiZmZlMDBjODZiYzRlZSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.H6zk_gSiudNdZTsgwYHFQnJiVXfR_BX5DfYNIoIsRv8"
115
+ }
116
+ for i in range(Number_of_Recommendation):
117
+ url = "https://api.themoviedb.org/3/movie/{id}?language=en-US".format(id = outputIds[i])
118
+ data_response = requests.get(url, headers=headers)
119
+ data = data_response.json()
120
+
121
+
122
+ url = "https://api.themoviedb.org/3/movie/{id}/videos?language=en-US".format(id = outputIds[i])
123
+ video_response = requests.get(url, headers=headers)
124
+ video = video_response.json()
125
+ video = get_video_address(video['results'])
126
+
127
+ url = "https://api.themoviedb.org/3/movie/{id}/images".format(id = outputIds[i])
128
+ image_response = requests.get(url, headers=headers)
129
+ image = image_response.json()
130
+ html +='''
131
+ <div class="bdy">
132
+ <div class = "top">
133
+ <div class="topleft">
134
+ <h1 class="name">'''+data['title']+'''</h1>
135
+ <div class="inline">
136
+ <h3>2022</h3>
137
+ <h3 class="time">'''+str(data['runtime']//60) + 'h ' + str(data['runtime']%60)+'''m</h3>
138
+ </div>
139
+ </div>
140
+ <div class="topright">
141
+ <h1>IMDb RATING</h1>
142
+ <h3>⭐'''+str(round(data['vote_average'], 2))+'''/10 &nbsp &nbsp '''+str(data['vote_count'])+'''</h3>
143
+ </div>
144
+
145
+ </div>
146
+ <div class="contents">
147
+ <img src='https://image.tmdb.org/t/p/w500'''+image['backdrops'][0]['file_path']+'''' class="img">
148
+ <iframe
149
+ src="https://www.youtube.com/embed/'''+video[0]+'''" class="video">
150
+ </iframe>
151
+ </div>
152
+ <h3>
153
+ '''+ data['overview']+'''
154
+ </h3>
155
+ </div>
156
+ </div>
157
+ '''
158
+ html += '''
159
+ </body>
160
+ </html>
161
+ '''
162
+
163
+
164
+ return html
165
+
166
+ html = ''
167
+
168
+ iface = gr.Interface(fn=recommend_movie,
169
+ inputs=[gr.Dataframe(headers=["Name", "Rate"],
170
+ datatype=["str", "number"],
171
+ row_count=3,
172
+ col_count=(2, "fixed")),
173
+ "number"
174
+ ],
175
+ outputs=gr.HTML(html),
176
+ title="Movie Recommender",
177
+ description="Enter a movie name and your rating (out of 10) for the movie. you must enter at least 3 movies and all words must start with capital letters, example : Grumpier Old Men",
178
+ css = css_code,
179
+ theme='darkhuggingface'
180
+ )
181
+
182
+ iface.launch()