Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,27 +7,29 @@ reranker = CrossEncoder("sentence-transformers/all-MiniLM-L12-v2")
|
|
7 |
|
8 |
def rerank_documents(query: str, documents: pd.DataFrame) -> pd.DataFrame:
|
9 |
documents = documents.copy()
|
10 |
-
documents = documents.drop_duplicates("
|
11 |
-
documents["rank"] = reranker.predict([[query, hit] for hit in documents["
|
12 |
documents = documents.sort_values(by="rank", ascending=False)
|
13 |
return documents
|
14 |
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
-
gr.Markdown("""# RAG -
|
18 |
|
19 |
-
|
|
|
|
|
20 |
|
21 |
query_input = gr.Textbox(
|
22 |
label="Query", placeholder="Enter your question here...", lines=3
|
23 |
)
|
24 |
documents_input = gr.Dataframe(
|
25 |
-
label="Documents", headers=["
|
26 |
)
|
27 |
|
28 |
submit_btn = gr.Button("Submit")
|
29 |
documents_output = gr.Dataframe(
|
30 |
-
label="Documents", headers=["
|
31 |
)
|
32 |
|
33 |
submit_btn.click(
|
|
|
7 |
|
8 |
def rerank_documents(query: str, documents: pd.DataFrame) -> pd.DataFrame:
|
9 |
documents = documents.copy()
|
10 |
+
documents = documents.drop_duplicates("text")
|
11 |
+
documents["rank"] = reranker.predict([[query, hit] for hit in documents["text"]])
|
12 |
documents = documents.sort_values(by="rank", ascending=False)
|
13 |
return documents
|
14 |
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
+
gr.Markdown("""# RAG - Augment
|
18 |
|
19 |
+
Applies reranking to the retrieved documents using [sentence-transformers/all-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L12-v2).
|
20 |
+
|
21 |
+
Part of [AI blueprint](https://github.com/huggingface/ai-blueprint) - a blueprint for AI development, focusing on practical examples of RAG, information extraction, analysis and fine-tuning in the age of LLMs.""")
|
22 |
|
23 |
query_input = gr.Textbox(
|
24 |
label="Query", placeholder="Enter your question here...", lines=3
|
25 |
)
|
26 |
documents_input = gr.Dataframe(
|
27 |
+
label="Documents", headers=["text"], wrap=True, interactive=True
|
28 |
)
|
29 |
|
30 |
submit_btn = gr.Button("Submit")
|
31 |
documents_output = gr.Dataframe(
|
32 |
+
label="Documents", headers=["text", "rank"], wrap=True
|
33 |
)
|
34 |
|
35 |
submit_btn.click(
|