Spaces:
Runtime error
Runtime error
from langchain.vectorstores import FAISS | |
from langchain.embeddings import SentenceTransformerEmbeddings | |
import gradio as gr | |
import reranking | |
embeddings = SentenceTransformerEmbeddings(model_name="multi-qa-MiniLM-L6-cos-v1") | |
db = FAISS.load_local('faiss_qa2', embeddings) | |
def main(query): | |
result_docs = db.similarity_search_with_score(query, k=20) | |
sentences = [doc[0].page_content for doc in result_docs] | |
score, index = reranking.search(query, sentences) | |
return result_docs[index][0].metadata['answer'], score, result_docs[index][0].page_content | |
demo = gr.Interface(fn=main, inputs="text", outputs=[ | |
gr.Textbox(label="Ответ, который будет показан клиенту"), | |
gr.Textbox(label="Score"), | |
gr.Textbox(label="Вопрос, по которому был найден ответ"), | |
]) | |
demo.launch() | |