Spaces:
Sleeping
Sleeping
import gradio as gr | |
from processing import md_to_passages | |
from pg import get_chapters | |
from vectors import match_query | |
def find_embedding(query: str): | |
top_res = match_query(query, 3) | |
# print(top_res) | |
chapters = get_chapters(list(map(lambda x: x["metadata"]["chapterId"], top_res))) | |
output = "" | |
for res, chapter in zip(top_res, chapters): | |
passages = md_to_passages(chapter["explanation"]) | |
output += f"{res['id']}\t| score: {res['score']:.2f}%\n{passages[res['passage_idx']]}\n\n" | |
return output | |
with gr.Blocks() as quesbook_search: | |
question = gr.Text(label="question") | |
answer = gr.Text(label="answer") | |
submit = gr.Button("Submit") | |
submit.click(fn=find_embedding, inputs=question, outputs=answer) | |
quesbook_search.launch() | |