Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,9 @@ import streamlit as st
|
|
3 |
import requests
|
4 |
import zipfile
|
5 |
from haystack.document_stores.in_memory import InMemoryDocumentStore
|
6 |
-
from haystack.
|
7 |
from haystack.pipelines.standard_pipelines import TextIndexingPipeline
|
8 |
-
from haystack.
|
9 |
from haystack.pipelines import ExtractiveQAPipeline
|
10 |
from pydantic import BaseModel
|
11 |
|
@@ -70,7 +70,7 @@ def initializing_Document_Store():
|
|
70 |
|
71 |
# Function to initialize the Retriever
|
72 |
def initializing_Retriever(document_store):
|
73 |
-
retriever =
|
74 |
document_store=document_store,
|
75 |
embedding_model="sentence-transformers/all-MiniLM-L6-v2"
|
76 |
)
|
@@ -79,14 +79,18 @@ def initializing_Retriever(document_store):
|
|
79 |
|
80 |
# Function to initialize the Reader
|
81 |
def initializing_Reader():
|
82 |
-
reader =
|
83 |
return reader
|
84 |
|
85 |
|
86 |
# Initializing components
|
87 |
document_store, retriever = initializing_Document_Store()
|
88 |
reader = initializing_Reader()
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
# User interaction via Streamlit
|
92 |
st.title("Ask about Game of Thrones!")
|
@@ -101,7 +105,12 @@ if user_query:
|
|
101 |
with st.spinner("Searching for an answer..."):
|
102 |
try:
|
103 |
# Use the pipeline to find the answer
|
104 |
-
answer =
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
# Display the answers
|
107 |
for idx, ans in enumerate(answer["answers"]):
|
|
|
3 |
import requests
|
4 |
import zipfile
|
5 |
from haystack.document_stores.in_memory import InMemoryDocumentStore
|
6 |
+
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
|
7 |
from haystack.pipelines.standard_pipelines import TextIndexingPipeline
|
8 |
+
from haystack.components.readers import ExtractiveReader
|
9 |
from haystack.pipelines import ExtractiveQAPipeline
|
10 |
from pydantic import BaseModel
|
11 |
|
|
|
70 |
|
71 |
# Function to initialize the Retriever
|
72 |
def initializing_Retriever(document_store):
|
73 |
+
retriever = InMemoryEmbeddingRetriever(
|
74 |
document_store=document_store,
|
75 |
embedding_model="sentence-transformers/all-MiniLM-L6-v2"
|
76 |
)
|
|
|
79 |
|
80 |
# Function to initialize the Reader
|
81 |
def initializing_Reader():
|
82 |
+
reader = ExtractiveReader(model="deepset/roberta-base-squad2")
|
83 |
return reader
|
84 |
|
85 |
|
86 |
# Initializing components
|
87 |
document_store, retriever = initializing_Document_Store()
|
88 |
reader = initializing_Reader()
|
89 |
+
reader.warm_up()
|
90 |
+
pipe = Pipeline()
|
91 |
+
pipe.add_component(instance=retriever, name="retriever")
|
92 |
+
pipe.add_component(instance=reader, name="reader")
|
93 |
+
pipe.connect("retriever.documents", "reader.documents")
|
94 |
|
95 |
# User interaction via Streamlit
|
96 |
st.title("Ask about Game of Thrones!")
|
|
|
105 |
with st.spinner("Searching for an answer..."):
|
106 |
try:
|
107 |
# Use the pipeline to find the answer
|
108 |
+
answer = pipeline.run(
|
109 |
+
data={
|
110 |
+
"retriever": {"query": question, "top_k": 10},
|
111 |
+
"reader": {"query": question, "top_k": top_k},
|
112 |
+
}
|
113 |
+
)
|
114 |
|
115 |
# Display the answers
|
116 |
for idx, ans in enumerate(answer["answers"]):
|