|
|
|
import gradio as gr |
|
from langchain.vectorstores import FAISS |
|
from langchain.embeddings import HuggingFaceEmbeddings |
|
|
|
|
|
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/LaBSE") |
|
|
|
|
|
vectorstore = FAISS.load_local("faiss_index", embedding_model, allow_dangerous_deserialization=True) |
|
manual_vectorstore = FAISS.load_local("faiss_manual_index", embedding_model, allow_dangerous_deserialization=True) |
|
problems_vectorstore = FAISS.load_local("faiss_problems_index", embedding_model, allow_dangerous_deserialization=True) |
|
|
|
def search_query(query): |
|
|
|
manual_results = manual_vectorstore.similarity_search(query, k=2) |
|
manual_output = "\n\n".join([doc.page_content for doc in manual_results]) |
|
|
|
|
|
problems_results = problems_vectorstore.similarity_search(query, k=2) |
|
problems_output = "\n\n".join([doc.page_content for doc in problems_results]) |
|
|
|
|
|
return manual_output, problems_output |
|
|
|
examples = [ |
|
["How to change the knife?"], |
|
["What are the safety precautions for using the machine?"], |
|
["How can I get help with the machine?"] |
|
] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=search_query, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."), |
|
outputs=[ |
|
gr.Textbox(label="Manual Results"), |
|
gr.Textbox(label="Issues Results") |
|
], |
|
examples=examples, |
|
title="Manual Querying System", |
|
description="Enter a question to get relevant information extracted from the manual and the most common related issues." |
|
) |
|
|
|
|
|
iface.launch() |