Spaces:
Sleeping
Sleeping
first commti
Browse files- .gitignore +2 -0
- app.py +45 -0
- requirements.txt +1 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.idea/
|
2 |
+
*.iml
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
from ragatouille import RAGPretrainedModel
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
dataset=load_dataset("davidr70/menachot")
|
6 |
+
documents = []
|
7 |
+
document_ids = []
|
8 |
+
metadatas = []
|
9 |
+
for row in dataset['train']:
|
10 |
+
document_id = row['id']
|
11 |
+
if document_id not in document_ids:
|
12 |
+
document_ids.append(document_id)
|
13 |
+
documents.append(row['content'])
|
14 |
+
metadatas.append(row['metadata'])
|
15 |
+
|
16 |
+
RAG = RAGPretrainedModel.from_pretrained("answerdotai/answerai-colbert-small-v1")
|
17 |
+
|
18 |
+
index_path = RAG.index(
|
19 |
+
index_name="menachot_small_model",
|
20 |
+
collection=documents,
|
21 |
+
document_ids=document_ids,
|
22 |
+
document_metadatas=metadatas
|
23 |
+
)
|
24 |
+
|
25 |
+
|
26 |
+
def ask(question):
|
27 |
+
results = RAG.search(question)
|
28 |
+
full_result = ""
|
29 |
+
for result in results:
|
30 |
+
output = f"document_id: {result['document_id']}\nscore: {str(result['score'])}\nrank: {str(result['rank'])}\ntext: {result['content']}\n\n\n"
|
31 |
+
full_result += output
|
32 |
+
return full_result
|
33 |
+
|
34 |
+
|
35 |
+
with gr.Blocks(title="Menachot Search") as demo:
|
36 |
+
gr.Markdown("# Menachot Search")
|
37 |
+
gr.Markdown("Search through the Menachot dataset using RAG")
|
38 |
+
|
39 |
+
question = gr.Textbox(label="Question", placeholder="Ask a question about Menachot...")
|
40 |
+
submit_btn = gr.Button("Search")
|
41 |
+
answer = gr.Textbox(label="Sources", lines=20)
|
42 |
+
|
43 |
+
submit_btn.click(fn=ask, inputs=question, outputs=answer)
|
44 |
+
|
45 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ragatouille
|