parasmech commited on
Commit
7aa0ced
·
verified ·
1 Parent(s): f8f92e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -10,6 +10,49 @@ warnings.filterwarnings("ignore")
10
  from langchain.document_loaders import TextLoader
11
  from langchain.text_splitter import CharacterTextSplitter
12
  from langchain.embeddings import HuggingFaceEmbeddings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  loader = TextLoader("/content/drive/MyDrive/Intelli_GenAI/RAG/Machine Learning Operations.txt")
15
  documents = loader.load()
 
10
  from langchain.document_loaders import TextLoader
11
  from langchain.text_splitter import CharacterTextSplitter
12
  from langchain.embeddings import HuggingFaceEmbeddings
13
+ from langchain.vectorstores import Pinecone as PineconeVectorStore
14
+ from langchain.llms import HuggingFaceHub
15
+ from langchain import PromptTemplate
16
+ from langchain.schema.runnable import RunnablePassthrough
17
+ from langchain.schema.output_parser import StrOutputParser
18
+
19
+
20
+ from pinecone import Pinecone, ServerlessSpec
21
+ pc = Pinecone(api_key=keyfile.PINECONE_API_KEY)
22
+ os.environ["PINECONE_API_KEY"] = keyfile.PINECONE_API_KEY
23
+
24
+
25
+ cloud = os.environ.get("PINECONE_CLOUD") or "aws"
26
+ region = os.environ.get("PINECONE_REGION") or "us-east-1"
27
+ serv = ServerlessSpec(cloud = cloud, region = region)
28
+
29
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
30
+ llm = HuggingFaceHub(
31
+ repo_id = model_id,
32
+ model_kwargs = {"temperature" : 0.8, "top_k" : 50},
33
+ huggingfacehub_api_token = userdata.get("HFToken")
34
+ )
35
+
36
+ index_name = "parasgupta"
37
+ # We are check if the name of our index is not existing in pinecone directory
38
+ if index_name not in pc.list_indexes().names():
39
+ # if not then we will create a index for us
40
+ pc.create_index(
41
+ name = index_name,
42
+ dimension = 768,
43
+ metric = "cosine",
44
+ spec = serv
45
+ )
46
+ while not pc.describe_index(index_name).status['ready']:
47
+ time.sleep(1)
48
+ # IF the index is not there in the index list
49
+ if index_name not in pc.list_indexes():
50
+ docsearch = PineconeVectorStore.from_documents(docs, embeddings, index_name = index_name)
51
+ else:
52
+ docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings, pinecone_index = pc.Index(index_name))
53
+
54
+
55
+
56
 
57
  loader = TextLoader("/content/drive/MyDrive/Intelli_GenAI/RAG/Machine Learning Operations.txt")
58
  documents = loader.load()