pminervini commited on
Commit
5de566b
1 Parent(s): 5b449d8
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -8,12 +8,6 @@ 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
- # model_name = "mistralai/Mistral-7B-Instruct-v0.2"
12
- model_name = "HuggingFaceH4/zephyr-7b-beta"
13
-
14
- # Load your language model from HuggingFace Transformers
15
- generator = pipeline("text-generation", model=model_name)
16
-
17
  def search(query, index="pubmed", num_results=3):
18
  """
19
  Search the Elasticsearch index for the most relevant documents.
@@ -34,14 +28,17 @@ def search(query, index="pubmed", num_results=3):
34
  # Extract and return the documents
35
  docs = [hit["_source"]["content"] for hit in response['hits']['hits']]
36
 
37
- print(f'Received {len(docs)} documents')
38
 
39
  return docs
40
 
41
- def rag_pipeline(prompt, index="pubmed"):
42
  """
43
  A simple RAG pipeline that retrieves documents and uses them to enrich the context for the LLM.
44
  """
 
 
 
45
  # Retrieve documents
46
  docs = search(prompt, index=index)
47
  joined_docs = '\n\n'.join(docs)
@@ -69,7 +66,8 @@ def rag_pipeline(prompt, index="pubmed"):
69
  iface = gr.Interface(fn=rag_pipeline,
70
  inputs=[
71
  gr.Textbox(label="Input Prompt", value="Are group 2 innate lymphoid cells (ILC2s) increased in chronic rhinosinusitis with nasal polyps or eosinophilia?"),
72
- gr.Dropdown(label="Elasticsearch Index", choices=["pubmed", "wikipedia", "textbooks"])
 
73
  ],
74
  outputs=[
75
  gr.Textbox(label="Generated Text"),
 
8
  basic_auth=('elastic', os.environ['ES_PASSWORD']),
9
  verify_certs=False, ssl_show_warn=False)
10
 
 
 
 
 
 
 
11
  def search(query, index="pubmed", num_results=3):
12
  """
13
  Search the Elasticsearch index for the most relevant documents.
 
28
  # Extract and return the documents
29
  docs = [hit["_source"]["content"] for hit in response['hits']['hits']]
30
 
31
+ print(f'Received {len(docs)} documents from index {index}')
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)
 
66
  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=[
73
  gr.Textbox(label="Generated Text"),