Spaces:
Runtime error
Runtime error
oryx1729
commited on
Commit
•
05feb2b
1
Parent(s):
a7f76fe
Add pipeline
Browse files
app.py
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
-
import sys
|
2 |
import logging
|
|
|
|
|
3 |
import streamlit as st
|
4 |
-
import
|
|
|
|
|
|
|
|
|
5 |
|
6 |
logging.basicConfig(
|
7 |
level=logging.DEBUG,
|
@@ -11,6 +16,29 @@ logging.basicConfig(
|
|
11 |
)
|
12 |
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import logging
|
2 |
+
import sys
|
3 |
+
|
4 |
import streamlit as st
|
5 |
+
from haystack import Document
|
6 |
+
from haystack import Pipeline
|
7 |
+
from haystack.document_stores import InMemoryDocumentStore
|
8 |
+
from haystack.nodes import EmbeddingRetriever
|
9 |
+
from haystack.nodes import FARMReader
|
10 |
|
11 |
logging.basicConfig(
|
12 |
level=logging.DEBUG,
|
|
|
16 |
)
|
17 |
|
18 |
|
19 |
+
def app_init():
|
20 |
+
docs = [Document(id='1', content='His name is John.'),
|
21 |
+
Document(id='2', content='Her name is Jane.'),
|
22 |
+
Document(id='3', content='My name is Haystack.')]
|
23 |
+
ds = InMemoryDocumentStore()
|
24 |
+
ds.write_documents(docs)
|
25 |
+
retriever = EmbeddingRetriever(
|
26 |
+
document_store=ds,
|
27 |
+
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
|
28 |
+
model_format="sentence_transformers",
|
29 |
+
)
|
30 |
+
ds.update_embeddings(retriever)
|
31 |
+
reader = FARMReader("deepset/minilm-uncased-squad2", use_gpu=False)
|
32 |
+
p = Pipeline()
|
33 |
+
p.add_node(component=retriever, name='retriever', inputs=['Query'])
|
34 |
+
p.add_node(component=reader, name='reader', inputs=['retriever'])
|
35 |
+
|
36 |
+
|
37 |
+
def main():
|
38 |
+
app_init()
|
39 |
+
st.title("Haystack Demo")
|
40 |
+
input = st.text_input("Query ...")
|
41 |
+
st.text(p.run(input))
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
main()
|