Spaces:
Runtime error
Runtime error
File size: 846 Bytes
05da059 cf67f9b 05da059 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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()
|