Spaces:
Sleeping
Sleeping
File size: 1,443 Bytes
ccdfaf9 71456b2 ccdfaf9 3be4587 ccdfaf9 3be4587 ccdfaf9 3be4587 ccdfaf9 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from datasets import load_dataset
from ragatouille import RAGPretrainedModel
import gradio as gr
dataset=load_dataset("davidr70/megillah_english_sugyot")
documents = []
document_ids = []
metadatas = []
for row in dataset['train']:
document_id = row['id']
if document_id not in document_ids:
document_ids.append(document_id)
documents.append(row['content'])
metadatas.append(row['metadata'])
RAG = RAGPretrainedModel.from_pretrained("answerdotai/answerai-colbert-small-v1")
index_path = RAG.index(
index_name="menachot_small_model",
collection=documents,
document_ids=document_ids,
document_metadatas=metadatas
)
def ask(question):
results = RAG.search(question)
full_result = ""
for result in results:
output = f"document_id: {result['document_id']}\nscore: {str(result['score'])}\nrank: {str(result['rank'])}\ntext: {result['content']}\n\n\n"
full_result += output
return full_result
with gr.Blocks(title="Megillah Search") as demo:
gr.Markdown("# Megillah Search")
gr.Markdown("Search through the Megillah dataset")
question = gr.Textbox(label="Question", placeholder="Ask a question about Megillah...")
submit_btn = gr.Button("Search")
answer = gr.Textbox(label="Sources", lines=20)
submit_btn.click(fn=ask, inputs=question, outputs=answer)
question.submit(fn=ask, inputs=question, outputs=answer)
demo.launch(share=True)
|