Atulkumar001 commited on
Commit
c04d9fd
·
verified ·
1 Parent(s): f42400b

Update build_database.py

Browse files
Files changed (1) hide show
  1. build_database.py +233 -81
build_database.py CHANGED
@@ -17,94 +17,248 @@ os.makedirs(
17
  exist_ok=True
18
  )
19
 
20
- os.makedirs(
21
- "data/processed",
22
- exist_ok=True
23
- )
24
-
25
  # =====================================================
26
- # FALLBACK TV DATA
27
- # (No scraping for now)
28
  # =====================================================
29
 
30
  documents = [
31
 
32
- {
33
- "series":
34
- "The Blacklist",
35
-
36
- "season": 1,
37
-
38
- "episode": 1,
39
-
40
- "title":
41
- "Pilot",
42
-
43
- "context":
44
- """
45
- REDDINGTON:
46
- I have a blacklist of
47
- dangerous criminals.
48
- Starting with Ranko Zamani.
49
- """
50
- },
51
-
52
- {
53
- "series":
54
- "The Blacklist",
55
-
56
- "season": 1,
57
-
58
- "episode": 1,
59
-
60
- "title":
61
- "Pilot",
62
 
63
- "context":
64
- """
65
- REDDINGTON:
66
- I want Elizabeth Keen
67
- specifically.
68
- """
69
- },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- {
72
- "series":
73
- "The Boys",
74
 
75
- "season": 1,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
- "episode": 1,
 
 
78
 
79
- "title":
80
- "The Name of the Game",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- "context":
83
- """
84
- HOMELANDER:
85
- Starlight joins
86
- The Seven.
87
- """
88
- },
89
 
90
- {
91
- "series":
92
- "Breaking Bad",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- "season": 1,
 
 
95
 
96
- "episode": 1,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
- "title":
99
- "Pilot",
 
100
 
101
- "context":
102
- """
103
- WALTER WHITE:
104
- I have cancer and
105
- decide to cook meth.
106
- """
107
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  ]
109
 
110
  # =====================================================
@@ -115,16 +269,14 @@ df = pd.DataFrame(
115
  documents
116
  )
117
 
118
- print(df.head())
 
 
119
 
120
  # =====================================================
121
- # EMBEDDING MODEL
122
  # =====================================================
123
 
124
- print(
125
- "Loading model..."
126
- )
127
-
128
  model = SentenceTransformer(
129
  "all-MiniLM-L6-v2"
130
  )
@@ -140,7 +292,7 @@ embeddings = np.array(
140
  ).astype("float32")
141
 
142
  # =====================================================
143
- # CREATE FAISS DB
144
  # =====================================================
145
 
146
  dimension = embeddings.shape[1]
@@ -154,7 +306,7 @@ index.add(
154
  )
155
 
156
  # =====================================================
157
- # SAVE DATABASE
158
  # =====================================================
159
 
160
  faiss.write_index(
@@ -173,5 +325,5 @@ with open(
173
  )
174
 
175
  print(
176
- "✅ Database created"
177
  )
 
17
  exist_ok=True
18
  )
19
 
 
 
 
 
 
20
  # =====================================================
21
+ # TV KNOWLEDGE DATABASE
 
22
  # =====================================================
23
 
24
  documents = [
25
 
26
+ # =====================================================
27
+ # THE BLACKLIST
28
+ # =====================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ {
31
+ "series":"The Blacklist",
32
+ "season":1,
33
+ "episode":1,
34
+ "title":"Pilot",
35
+ "context":
36
+ """
37
+ Reddington surrenders to the FBI
38
+ and demands to work only with
39
+ Elizabeth Keen.
40
+ """
41
+ },
42
+
43
+ {
44
+ "series":"The Blacklist",
45
+ "season":1,
46
+ "episode":1,
47
+ "title":"Pilot",
48
+ "context":
49
+ """
50
+ Reddington introduces
51
+ the blacklist,
52
+ a secret list of dangerous
53
+ criminals.
54
+ """
55
+ },
56
+
57
+ {
58
+ "series":"The Blacklist",
59
+ "season":1,
60
+ "episode":1,
61
+ "title":"Pilot",
62
+ "context":
63
+ """
64
+ Ranko Zamani is identified
65
+ as a dangerous criminal
66
+ targeting a general's daughter.
67
+ """
68
+ },
69
 
70
+ # =====================================================
71
+ # BREAKING BAD
72
+ # =====================================================
73
 
74
+ {
75
+ "series":"Breaking Bad",
76
+ "season":1,
77
+ "episode":1,
78
+ "title":"Pilot",
79
+ "context":
80
+ """
81
+ Walter White discovers he has
82
+ lung cancer and starts making
83
+ methamphetamine to support
84
+ his family.
85
+ """
86
+ },
87
+
88
+ {
89
+ "series":"Breaking Bad",
90
+ "season":2,
91
+ "episode":8,
92
+ "title":"Better Call Saul",
93
+ "context":
94
+ """
95
+ Saul Goodman becomes Walter
96
+ White's lawyer and helps him
97
+ expand his illegal drug business.
98
+ """
99
+ },
100
+
101
+ {
102
+ "series":"Breaking Bad",
103
+ "season":5,
104
+ "episode":16,
105
+ "title":"Felina",
106
+ "context":
107
+ """
108
+ Walter White sacrifices himself
109
+ after rescuing Jesse Pinkman.
110
+ """
111
+ },
112
 
113
+ # =====================================================
114
+ # THE BOYS
115
+ # =====================================================
116
 
117
+ {
118
+ "series":"The Boys",
119
+ "season":1,
120
+ "episode":1,
121
+ "title":"The Name of the Game",
122
+ "context":
123
+ """
124
+ Starlight joins The Seven while
125
+ Homelander is introduced as
126
+ its dangerous leader.
127
+ """
128
+ },
129
+
130
+ {
131
+ "series":"The Boys",
132
+ "season":2,
133
+ "episode":8,
134
+ "title":"What I Know",
135
+ "context":
136
+ """
137
+ Starlight helps expose
138
+ Homelander and Vought.
139
+ """
140
+ },
141
+
142
+ {
143
+ "series":"The Boys",
144
+ "season":3,
145
+ "episode":8,
146
+ "title":"The Instant White-Hot Wild",
147
+ "context":
148
+ """
149
+ Butcher and Homelander
150
+ continue their rivalry.
151
+ """
152
+ },
153
 
154
+ # =====================================================
155
+ # GAME OF THRONES
156
+ # =====================================================
 
 
 
 
157
 
158
+ {
159
+ "series":"Game of Thrones",
160
+ "season":1,
161
+ "episode":9,
162
+ "title":"Baelor",
163
+ "context":
164
+ """
165
+ Ned Stark is publicly executed
166
+ on King Joffrey's orders.
167
+ """
168
+ },
169
+
170
+ {
171
+ "series":"Game of Thrones",
172
+ "season":3,
173
+ "episode":9,
174
+ "title":"The Rains of Castamere",
175
+ "context":
176
+ """
177
+ The Red Wedding results in
178
+ the deaths of Robb Stark,
179
+ Talisa and Catelyn Stark.
180
+ """
181
+ },
182
+
183
+ {
184
+ "series":"Game of Thrones",
185
+ "season":8,
186
+ "episode":6,
187
+ "title":"The Iron Throne",
188
+ "context":
189
+ """
190
+ Jon Snow kills Daenerys
191
+ to stop her violent rule.
192
+ """
193
+ },
194
 
195
+ # =====================================================
196
+ # FRIENDS
197
+ # =====================================================
198
 
199
+ {
200
+ "series":"Friends",
201
+ "season":1,
202
+ "episode":1,
203
+ "title":"Pilot",
204
+ "context":
205
+ """
206
+ Rachel leaves Barry at the altar
207
+ and reconnects with Monica.
208
+ """
209
+ },
210
+
211
+ {
212
+ "series":"Friends",
213
+ "season":5,
214
+ "episode":14,
215
+ "title":"Everybody Finds Out",
216
+ "context":
217
+ """
218
+ The group discovers Monica and
219
+ Chandler are secretly dating.
220
+ """
221
+ },
222
+
223
+ {
224
+ "series":"Friends",
225
+ "season":10,
226
+ "episode":18,
227
+ "title":"The Last One",
228
+ "context":
229
+ """
230
+ Ross and Rachel reunite.
231
+ The friends leave the apartment.
232
+ """
233
+ },
234
 
235
+ # =====================================================
236
+ # STRANGER THINGS
237
+ # =====================================================
238
 
239
+ {
240
+ "series":"Stranger Things",
241
+ "season":1,
242
+ "episode":1,
243
+ "title":"Chapter One",
244
+ "context":
245
+ """
246
+ Will Byers disappears and Eleven
247
+ appears mysteriously.
248
+ """
249
+ },
250
+
251
+ {
252
+ "series":"Stranger Things",
253
+ "season":4,
254
+ "episode":9,
255
+ "title":"The Piggyback",
256
+ "context":
257
+ """
258
+ Eleven battles Vecna while
259
+ Max is critically injured.
260
+ """
261
+ }
262
  ]
263
 
264
  # =====================================================
 
269
  documents
270
  )
271
 
272
+ print(
273
+ f"Loaded {len(df)} entries"
274
+ )
275
 
276
  # =====================================================
277
+ # EMBEDDINGS
278
  # =====================================================
279
 
 
 
 
 
280
  model = SentenceTransformer(
281
  "all-MiniLM-L6-v2"
282
  )
 
292
  ).astype("float32")
293
 
294
  # =====================================================
295
+ # FAISS
296
  # =====================================================
297
 
298
  dimension = embeddings.shape[1]
 
306
  )
307
 
308
  # =====================================================
309
+ # SAVE
310
  # =====================================================
311
 
312
  faiss.write_index(
 
325
  )
326
 
327
  print(
328
+ "✅ Entertainment database built"
329
  )