ababio commited on
Commit
e6f156e
1 Parent(s): 9eeafb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1,13 +1,22 @@
1
  import os
2
  from getpass import getpass
3
  import gradio as gr
 
 
4
 
5
- pinecone_api_key = os.getenv("PINECONE_API_KEY") or getpass("Enter your Pinecone API Key: ")
6
- openai_api_key = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API Key: ")
7
-
8
  from llama_index.node_parser import SemanticSplitterNodeParser
9
  from llama_index.embeddings import OpenAIEmbedding
10
  from llama_index.ingestion import IngestionPipeline
 
 
 
 
 
 
 
11
 
12
  # This will be the model we use both for Node parsing and for vectorization
13
  embed_model = OpenAIEmbedding(api_key=openai_api_key)
@@ -24,10 +33,7 @@ pipeline = IngestionPipeline(
24
  ],
25
  )
26
 
27
- from pinecone.grpc import PineconeGRPC
28
- from pinecone import ServerlessSpec
29
 
30
- from llama_index.vector_stores import PineconeVectorStore
31
 
32
  # Initialize connection to Pinecone
33
  pc = PineconeGRPC(api_key=pinecone_api_key)
@@ -41,8 +47,6 @@ vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
41
 
42
  pinecone_index.describe_index_stats()
43
 
44
- from llama_index import VectorStoreIndex
45
- from llama_index.retrievers import VectorIndexRetriever
46
 
47
  # Due to how LlamaIndex works here, if your Open AI API key was
48
  # not set to an environment variable before, you have to set it at this point
@@ -55,7 +59,6 @@ vector_index = VectorStoreIndex.from_vector_store(vector_store=vector_store)
55
  # Grab 5 search results
56
  retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5)
57
 
58
- from llama_index.query_engine import RetrieverQueryEngine
59
 
60
  # Pass in your retriever from above, which is configured to return the top 5 results
61
  query_engine = RetrieverQueryEngine(retriever=retriever)
 
1
  import os
2
  from getpass import getpass
3
  import gradio as gr
4
+ from pinecone.grpc import PineconeGRPC
5
+ from pinecone import ServerlessSpec
6
 
7
+ from llama_index.vector_stores import PineconeVectorStore
8
+ from llama_index import VectorStoreIndex
9
+ from llama_index.retrievers import VectorIndexRetriever
10
  from llama_index.node_parser import SemanticSplitterNodeParser
11
  from llama_index.embeddings import OpenAIEmbedding
12
  from llama_index.ingestion import IngestionPipeline
13
+ from llama_index.query_engine import RetrieverQueryEngine
14
+
15
+
16
+
17
+ pinecone_api_key = os.getenv("PINECONE_API_KEY")
18
+ openai_api_key = os.getenv("OPENAI_API_KEY")
19
+
20
 
21
  # This will be the model we use both for Node parsing and for vectorization
22
  embed_model = OpenAIEmbedding(api_key=openai_api_key)
 
33
  ],
34
  )
35
 
 
 
36
 
 
37
 
38
  # Initialize connection to Pinecone
39
  pc = PineconeGRPC(api_key=pinecone_api_key)
 
47
 
48
  pinecone_index.describe_index_stats()
49
 
 
 
50
 
51
  # Due to how LlamaIndex works here, if your Open AI API key was
52
  # not set to an environment variable before, you have to set it at this point
 
59
  # Grab 5 search results
60
  retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5)
61
 
 
62
 
63
  # Pass in your retriever from above, which is configured to return the top 5 results
64
  query_engine = RetrieverQueryEngine(retriever=retriever)