Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,8 @@ import pandas as pd
|
|
3 |
|
4 |
from haystack.schema import Answer
|
5 |
from haystack.document_stores import InMemoryDocumentStore
|
6 |
-
from haystack.pipelines import FAQPipeline
|
7 |
-
from haystack.
|
8 |
from haystack.utils import print_answers
|
9 |
import logging
|
10 |
|
@@ -15,7 +15,7 @@ def start_haystack():
|
|
15 |
retriever = EmbeddingRetriever(document_store=document_store, embedding_model='sentence-transformers/all-MiniLM-L6-v2', use_gpu=True, top_k=1)
|
16 |
load_data_to_store(document_store,retriever)
|
17 |
pipeline = FAQPipeline(retriever=retriever)
|
18 |
-
return pipeline
|
19 |
|
20 |
def load_data_to_store(document_store, retriever):
|
21 |
df = pd.read_csv('monopoly_qa-v1.csv')
|
@@ -26,11 +26,11 @@ def load_data_to_store(document_store, retriever):
|
|
26 |
|
27 |
dicts = df.to_dict(orient="records")
|
28 |
document_store.write_documents(dicts)
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
def predict(question):
|
33 |
-
prediction = pipeline.run(question)
|
34 |
answer = prediction["answers"][0].meta
|
35 |
faq_response = "FAQ Question: " + answer["query"] + "\n"+"Answer: " + answer["answer"]
|
36 |
return faq_response
|
@@ -39,10 +39,14 @@ input_question =gr.inputs.Textbox(label="enter your monopoly question here")
|
|
39 |
response = "text"
|
40 |
examples = ["how much cash do we get to start with?", "at what point can I buy houses?", "what happens when I land on free parking?"]
|
41 |
|
42 |
-
gr.Interface(
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
from haystack.schema import Answer
|
5 |
from haystack.document_stores import InMemoryDocumentStore
|
6 |
+
from haystack.pipelines import FAQPipeline, ExtractiveQAPipeline
|
7 |
+
from haystack.nodes import EmbeddingRetriever, TfidfRetriever, FARMReader
|
8 |
from haystack.utils import print_answers
|
9 |
import logging
|
10 |
|
|
|
15 |
retriever = EmbeddingRetriever(document_store=document_store, embedding_model='sentence-transformers/all-MiniLM-L6-v2', use_gpu=True, top_k=1)
|
16 |
load_data_to_store(document_store,retriever)
|
17 |
pipeline = FAQPipeline(retriever=retriever)
|
18 |
+
return pipeline, document_store
|
19 |
|
20 |
def load_data_to_store(document_store, retriever):
|
21 |
df = pd.read_csv('monopoly_qa-v1.csv')
|
|
|
26 |
|
27 |
dicts = df.to_dict(orient="records")
|
28 |
document_store.write_documents(dicts)
|
29 |
+
|
30 |
+
faq_pipeline, doc_store = start_haystack()
|
31 |
|
32 |
+
def predict_faq(question):
|
33 |
+
prediction = faq_pipeline.run(question)
|
|
|
|
|
34 |
answer = prediction["answers"][0].meta
|
35 |
faq_response = "FAQ Question: " + answer["query"] + "\n"+"Answer: " + answer["answer"]
|
36 |
return faq_response
|
|
|
39 |
response = "text"
|
40 |
examples = ["how much cash do we get to start with?", "at what point can I buy houses?", "what happens when I land on free parking?"]
|
41 |
|
42 |
+
mon_faq = gr.Interface(
|
43 |
+
fn=predict_faq,
|
44 |
+
inputs=input_question,
|
45 |
+
outputs=response,
|
46 |
+
examples=examples,
|
47 |
+
title="Monopoly FAQ Semantic Search")
|
48 |
+
|
49 |
+
feedback_answer =
|
50 |
+
|
51 |
+
def return_feedback(input_question,feedback_answer):
|
52 |
+
|