nickmuchi commited on
Commit
81258cc
·
1 Parent(s): 6b6aacf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -29,10 +29,10 @@ from langchain.prompts import PromptTemplate
29
 
30
  prefix_messages = [{"role": "system", "content": "You are a helpful assistant that is very good at answering questions about investments using the information given."}]
31
 
32
- model_options = {'all-mpnet-base-v2': "sentence-transformers/all-mpnet-base-v2",
33
- 'instructor-base': "hkunlp/instructor-base"}
34
 
35
- model_options_list = list(model_options.keys())
36
 
37
  memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True, output_key='answer')
38
 
@@ -66,28 +66,21 @@ def load_prompt():
66
 
67
  return prompt
68
 
69
- def load_vectorstore(model):
70
  '''load embeddings and vectorstore'''
71
-
72
- if 'mpnet' in model:
73
-
74
- emb = HuggingFaceEmbeddings(model_name=model)
75
- return FAISS.load_local('vanguard-embeddings', emb)
76
-
77
- elif 'instructor'in model:
78
 
79
- emb = HuggingFaceInstructEmbeddings(model_name=model,
80
- query_instruction='Represent the Financial question for retrieving supporting paragraphs: ',
81
- embed_instruction='Represent the Financial paragraph for retrieval: ')
82
- return FAISS.load_local('vanguard_embeddings_inst', emb)
83
 
84
  #default embeddings and store
85
- vectorstore = load_vectorstore(model_options['all-mpnet-base-v2'])
86
 
87
- def on_value_change(change):
88
- '''When radio changes, change the embeddings'''
 
89
  global vectorstore
90
- vectorstore = load_vectorstore(model_options[change])
91
 
92
  # vectorstore = load_vectorstore('vanguard-embeddings',sbert_emb)
93
 
@@ -165,15 +158,11 @@ with block:
165
  gr.Markdown("<h3><center>Chat-Your-Data (Investor Education)</center></h3>")
166
  embed_but = gr.Button(value='Load QA Chain')
167
  with gr.Row():
168
- websites = gr.Radio(choices=data_options,value=data_options[0],label='Select US or AUS website data',
169
  interactive=True)
170
  websites.change(on_value_change, websites)
171
- with gr.Row():
172
- embeddings = gr.Radio(choices=model_options_list,value=model_options_list[0], label='Choose your Embedding Model',
173
- interactive=True)
174
- embeddings.change(on_value_change, embeddings)
175
 
176
- vectorstore = load_vectorstore(embeddings.value)
177
 
178
  chatbot = gr.Chatbot()
179
 
 
29
 
30
  prefix_messages = [{"role": "system", "content": "You are a helpful assistant that is very good at answering questions about investments using the information given."}]
31
 
32
+ site_options = {'US': 'vanguard_embeddings_US',
33
+ 'AUS': 'vanguard_embeddings'}
34
 
35
+ site_options_list = list(site_options.keys())
36
 
37
  memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True, output_key='answer')
38
 
 
66
 
67
  return prompt
68
 
69
+ def load_vectorstore(site):
70
  '''load embeddings and vectorstore'''
 
 
 
 
 
 
 
71
 
72
+ emb = HuggingFaceEmbeddings(model_name="all-mpnet-base-v2")
73
+
74
+ return FAISS.load_local(site, emb)
 
75
 
76
  #default embeddings and store
77
+ vectorstore = load_vectorstore(website_options_list_options[0])
78
 
79
+ def on_value_change(site):
80
+ '''When radio changes, change the website reference data'''
81
+
82
  global vectorstore
83
+ vectorstore = load_vectorstore(site)
84
 
85
  # vectorstore = load_vectorstore('vanguard-embeddings',sbert_emb)
86
 
 
158
  gr.Markdown("<h3><center>Chat-Your-Data (Investor Education)</center></h3>")
159
  embed_but = gr.Button(value='Load QA Chain')
160
  with gr.Row():
161
+ websites = gr.Radio(choices=site_options_list,value=site_options_list[0],label='Select US or AUS website data',
162
  interactive=True)
163
  websites.change(on_value_change, websites)
 
 
 
 
164
 
165
+ vectorstore = load_vectorstore(websites.value)
166
 
167
  chatbot = gr.Chatbot()
168