Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,8 +51,8 @@ phi2 = pipeline(
|
|
| 51 |
) # GPU
|
| 52 |
hf_model = HuggingFacePipeline(pipeline=phi2)
|
| 53 |
|
| 54 |
-
# Returns a faiss vector store given a txt file
|
| 55 |
-
def
|
| 56 |
# Load data
|
| 57 |
loader = UnstructuredFileLoader(filename)
|
| 58 |
raw_documents = loader.load()
|
|
@@ -71,13 +71,13 @@ def prepare_vector_store(filename):
|
|
| 71 |
embeddings = HuggingFaceEmbeddings()
|
| 72 |
vectorstore = FAISS.from_documents(documents, embeddings)
|
| 73 |
|
| 74 |
-
return vectorstore
|
| 75 |
|
| 76 |
# Retrieveal QA chian
|
| 77 |
def get_retrieval_qa_chain(text_file):
|
| 78 |
-
retriever =
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
chain = RetrievalQA.from_chain_type(
|
| 83 |
llm=hf_model,
|
|
@@ -115,6 +115,8 @@ with gr.Blocks() as demo:
|
|
| 115 |
""")
|
| 116 |
|
| 117 |
default_text_file = "Oppenheimer-movie-wiki.txt"
|
|
|
|
|
|
|
| 118 |
text_file = gr.State(default_text_file)
|
| 119 |
|
| 120 |
gr.Markdown("## Upload a txt file or Use the Default 'Oppenheimer-movie-wiki.txt' that has already been loaded")
|
|
|
|
| 51 |
) # GPU
|
| 52 |
hf_model = HuggingFacePipeline(pipeline=phi2)
|
| 53 |
|
| 54 |
+
# Returns a faiss vector store retriever given a txt file
|
| 55 |
+
def prepare_vector_store_retriever(filename):
|
| 56 |
# Load data
|
| 57 |
loader = UnstructuredFileLoader(filename)
|
| 58 |
raw_documents = loader.load()
|
|
|
|
| 71 |
embeddings = HuggingFaceEmbeddings()
|
| 72 |
vectorstore = FAISS.from_documents(documents, embeddings)
|
| 73 |
|
| 74 |
+
return VectorStoreRetriever(vectorstore=vectorstore)
|
| 75 |
|
| 76 |
# Retrieveal QA chian
|
| 77 |
def get_retrieval_qa_chain(text_file):
|
| 78 |
+
retriever = default_retriever
|
| 79 |
+
if text_file != default_text_file:
|
| 80 |
+
retriever = prepare_vector_store_retriever(text_file)
|
| 81 |
|
| 82 |
chain = RetrievalQA.from_chain_type(
|
| 83 |
llm=hf_model,
|
|
|
|
| 115 |
""")
|
| 116 |
|
| 117 |
default_text_file = "Oppenheimer-movie-wiki.txt"
|
| 118 |
+
default_retriever = prepare_vector_store_retriever(default_text_file)
|
| 119 |
+
|
| 120 |
text_file = gr.State(default_text_file)
|
| 121 |
|
| 122 |
gr.Markdown("## Upload a txt file or Use the Default 'Oppenheimer-movie-wiki.txt' that has already been loaded")
|