Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from haystack.utils import fetch_archive_from_http, clean_wiki_text, convert_files_to_docs | |
| from haystack.document_stores import InMemoryDocumentStore | |
| from haystack.pipelines import ExtractiveQAPipeline | |
| from haystack.nodes import FARMReader, TfidfRetriever | |
| import validators | |
| import json | |
| doc_dir = './article_txt_got' | |
| document_store = InMemoryDocumentStore() | |
| docs = convert_files_to_docs(dir_path=doc_dir, clean_func=clean_wiki_text, split_paragraphs=True) | |
| document_store.write_documents(docs) | |
| retriever = TfidfRetriever(document_store=document_store) | |
| reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2", use_gpu=True) | |
| pipeline = ExtractiveQAPipeline(reader, retriever) | |
| def ask_question(question): | |
| prediction = pipeline.run(query=question, params={"Retriever": {"top_k": 10}, "Reader": {"top_k": 5}}) | |
| st.write(prediction['answers'][0]) | |
| st.write(prediction['answers'][1]) | |
| st.write(prediction['answers'][2]) | |
| #Streamlit App | |
| st.set_page_config(page_title='Game of Thrones QA with Haystack') | |
| question = st.text_input(label="Ask a Question about Game of Thromes", value="Who is Arya's father?") | |
| if question: | |
| ask_question(question) |