Spaces:
Runtime error
Runtime error
File size: 1,037 Bytes
8c03ef3 be7baa9 8c03ef3 be7baa9 8c03ef3 aec45ab 8c03ef3 fe60e2b 0b5cc56 fe60e2b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
import pandas as pd
import faiss
from sentence_transformers import SentenceTransformer
#load the sentences data
path = "debate_hansard_sentences.txt"
file = open(path, "r")
sentences = file.readlines()
# remove duplicates
sentences = [word for word in list(set(sentences)) if type(word)]
sentences_dict = {idx:val for idx, val in enumerate(sentences)}
sentences_df = pd.DataFrame.from_dict(sentences_dict, orient='index', columns=['sentences'])
#load the index
index = faiss.read_index("semantic_search_vector.index")
def question_answer(query):
model = SentenceTransformer('bert-base-nli-mean-tokens')
k = 4
xq = model.encode([query])
D, I = index.search(xq, k) # search
sentences_df["sentences"].iloc[I.tolist()[0]]
a = list(sentences_df["sentences"].iloc[I.tolist()[0]])
results = "\n".join(a)
answer = results
return answer
iface = gr.Interface(
fn=question_answer,
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your query here"),
outputs="text").launch()
|