forked from jbellis/cassgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.py
More file actions
36 lines (29 loc) · 1 KB
/
load.py
File metadata and controls
36 lines (29 loc) · 1 KB
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
import base64
import json
from cassandra.cluster import Cluster
from db import DB
from tqdm.auto import tqdm
from concurrent.futures import ThreadPoolExecutor
import threading
import time
thread_local_storage = threading.local()
def get_db_handle():
if not hasattr(thread_local_storage, 'db_handle'):
thread_local_storage.db_handle = DB('demo', 'youtube_transcriptions')
return thread_local_storage.db_handle
def upsert_row(row):
db = get_db_handle()
row['embedding'] = base64.b64decode(row['embedding'])
db.upsert_one(row)
def main():
print("Waiting for Cassandra schema")
get_db_handle() # let one thread create the table + index
time.sleep(1)
with open('youtube_transcriptions.json', 'r') as f:
data = json.load(f)
num_threads = 8
with ThreadPoolExecutor(max_workers=num_threads) as executor:
list(tqdm(executor.map(upsert_row, data), total=len(data)))
print('Data imported from youtube_transcriptions.json')
if __name__ == '__main__':
main()