Spaces:
Sleeping
Sleeping
File size: 783 Bytes
bb3407a |
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 |
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()
|