gen-ai-demo-3 / train.py
cowcow02's picture
Upload folder using huggingface_hub
e9e8863
raw
history blame
1.01 kB
from pathlib import Path
import openai
import pinecone
from llama_index import StorageContext, VectorStoreIndex, download_loader
from llama_index.vector_stores import PineconeVectorStore
from environments import PINECONE_API_KEY, PINECONE_INDEX, OPENAI_API_KEY
openai.api_key = OPENAI_API_KEY
print('Start Loading Data ...')
# PagedCSVReader = download_loader("PagedCSVReader")
# loader = PagedCSVReader(encoding="utf-8")
# documents = loader.load_data(file=Path('train-assets/training-target-simple.csv'))
PDFReader = download_loader("PDFReader")
loader = PDFReader()
documents = loader.load_data(file=Path('./train-assets/faq.pdf'))
pinecone.init(
api_key=PINECONE_API_KEY,
environment='gcp-starter'
)
pinecone_index = pinecone.Index(PINECONE_INDEX)
vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
print('Done!')