Spaces:
Sleeping
Sleeping
pminervini
commited on
Commit
•
4cf3bf5
1
Parent(s):
5de566b
update
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ es = Elasticsearch(hosts=["https://data.neuralnoise.com:9200"],
|
|
8 |
basic_auth=('elastic', os.environ['ES_PASSWORD']),
|
9 |
verify_certs=False, ssl_show_warn=False)
|
10 |
|
11 |
-
def search(query, index="pubmed",
|
12 |
"""
|
13 |
Search the Elasticsearch index for the most relevant documents.
|
14 |
"""
|
@@ -20,7 +20,7 @@ def search(query, index="pubmed", num_results=3):
|
|
20 |
"match": {
|
21 |
"content": query # Assuming documents have a 'content' field
|
22 |
}
|
23 |
-
}, "size":
|
24 |
}
|
25 |
|
26 |
response = es.options(request_timeout=60).search(index=index, body=es_request_body)
|
@@ -32,15 +32,17 @@ def search(query, index="pubmed", num_results=3):
|
|
32 |
|
33 |
return docs
|
34 |
|
35 |
-
def rag_pipeline(prompt, index="pubmed", model_name="HuggingFaceH4/zephyr-7b-beta"):
|
36 |
"""
|
37 |
A simple RAG pipeline that retrieves documents and uses them to enrich the context for the LLM.
|
38 |
"""
|
39 |
# Load your language model from HuggingFace Transformers
|
40 |
generator = pipeline("text-generation", model=model_name)
|
41 |
|
|
|
|
|
42 |
# Retrieve documents
|
43 |
-
docs = search(prompt, index=index)
|
44 |
joined_docs = '\n\n'.join(docs)
|
45 |
|
46 |
messages = [
|
@@ -67,6 +69,7 @@ iface = gr.Interface(fn=rag_pipeline,
|
|
67 |
inputs=[
|
68 |
gr.Textbox(label="Input Prompt", value="Are group 2 innate lymphoid cells (ILC2s) increased in chronic rhinosinusitis with nasal polyps or eosinophilia?"),
|
69 |
gr.Dropdown(label="Index", choices=["pubmed", "wikipedia", "textbooks"], value="pubmed"),
|
|
|
70 |
gr.Dropdown(label="Model", choices=["HuggingFaceH4/zephyr-7b-beta", "meta-llama/Llama-2-7b-chat-hf", "meta-llama/Llama-2-13b-chat-hf", "meta-llama/Llama-2-70b-chat-hf"], value="HuggingFaceH4/zephyr-7b-beta")
|
71 |
],
|
72 |
outputs=[
|
|
|
8 |
basic_auth=('elastic', os.environ['ES_PASSWORD']),
|
9 |
verify_certs=False, ssl_show_warn=False)
|
10 |
|
11 |
+
def search(query, index="pubmed", num_docs=3):
|
12 |
"""
|
13 |
Search the Elasticsearch index for the most relevant documents.
|
14 |
"""
|
|
|
20 |
"match": {
|
21 |
"content": query # Assuming documents have a 'content' field
|
22 |
}
|
23 |
+
}, "size": num_docs
|
24 |
}
|
25 |
|
26 |
response = es.options(request_timeout=60).search(index=index, body=es_request_body)
|
|
|
32 |
|
33 |
return docs
|
34 |
|
35 |
+
def rag_pipeline(prompt, index="pubmed", num_docs=3, model_name="HuggingFaceH4/zephyr-7b-beta"):
|
36 |
"""
|
37 |
A simple RAG pipeline that retrieves documents and uses them to enrich the context for the LLM.
|
38 |
"""
|
39 |
# Load your language model from HuggingFace Transformers
|
40 |
generator = pipeline("text-generation", model=model_name)
|
41 |
|
42 |
+
num_docs = int(num_docs)
|
43 |
+
|
44 |
# Retrieve documents
|
45 |
+
docs = search(prompt, index=index, num_docs=num_docs)
|
46 |
joined_docs = '\n\n'.join(docs)
|
47 |
|
48 |
messages = [
|
|
|
69 |
inputs=[
|
70 |
gr.Textbox(label="Input Prompt", value="Are group 2 innate lymphoid cells (ILC2s) increased in chronic rhinosinusitis with nasal polyps or eosinophilia?"),
|
71 |
gr.Dropdown(label="Index", choices=["pubmed", "wikipedia", "textbooks"], value="pubmed"),
|
72 |
+
gr.Number(label="Number of Documents", value=3, step=1, min_value=1, max_value=10),
|
73 |
gr.Dropdown(label="Model", choices=["HuggingFaceH4/zephyr-7b-beta", "meta-llama/Llama-2-7b-chat-hf", "meta-llama/Llama-2-13b-chat-hf", "meta-llama/Llama-2-70b-chat-hf"], value="HuggingFaceH4/zephyr-7b-beta")
|
74 |
],
|
75 |
outputs=[
|