-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata_embeddings.py
42 lines (36 loc) · 1.24 KB
/
metadata_embeddings.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
import json
import pandas as pd
import openai
from langchain.llms import OpenAI
import openai_functions
from langchain.document_loaders import TextLoader
import time
import os
os.OPENAI_API_KEY ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
openai_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
metadata_filepath = 'Digital X Solution Catalog Metadata for Hack to the Rescue.xlsx'
def display_json(json_str):
for key in json.loads(json_str).keys():
print(key,':',json.loads(json_str)[key])
def get_json_data(metadata_filepath):
catalog_data = pd.read_excel(metadata_filepath)
list_of_jsons = catalog_data.to_json(orient='records', lines=True).splitlines()
json_data_strings = []
for json_obj in list_of_jsons:
json_str = json.dumps(json_obj)
json_str = json_str.replace('\\','')
json_data_strings.append(json_str)
print("No of json strings ",len(json_data_strings))
f = open("sample.txt",'w')
for jstr in json_data_strings:
f.write(jstr)
total_pages = []
for doc in json_data_strings:
f = open("file.txt",'w')
f.write(doc)
f.close()
loader = TextLoader("file.txt")
pages = loader.load()
total_pages.extend(pages)
pages_doc = pages
return json_data_strings