nickmuchi commited on
Commit
f187dab
·
1 Parent(s): c5c1dff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -9,18 +9,27 @@ import gradio as gr
9
  import pickle
10
  from threading import Lock
11
 
12
- model_sbert = "sentence-transformers/all-mpnet-base-v2"
 
13
 
 
 
14
 
15
- sbert_emb = HuggingFaceEmbeddings(model_name=model_sbert)
 
 
16
 
17
- def load_vectorstore(folder,embeddings):
18
-
19
- vectorstore = FAISS.load_local(folder,embeddings)
 
 
 
 
 
20
 
21
- return vectorstore
22
 
23
- vectorstore = load_vectorstore('vanguard-embeddings',sbert_emb)
24
 
25
  _template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
26
  You can assume the question about investing and the investment management industry.
@@ -104,6 +113,10 @@ with block:
104
  type="password",
105
  )
106
 
 
 
 
 
107
  chatbot = gr.Chatbot()
108
 
109
  with gr.Row():
@@ -133,6 +146,7 @@ with block:
133
  state = gr.State()
134
  agent_state = gr.State()
135
 
 
136
  submit.click(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
137
  message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
138
 
 
9
  import pickle
10
  from threading import Lock
11
 
12
+ model_options = {'all-mpnet-base-v2': "sentence-transformers/all-mpnet-base-v2",
13
+ 'instructor-base'}: "hkunlp/instructor-base"}
14
 
15
+ def load_vectorstore(model):
16
+ '''load embeddings and vectorstore'''
17
 
18
+ if 'mpnet' in model:
19
+
20
+ emb = HuggingFaceEmbeddings(model_name=model)
21
 
22
+ return FAISS.load_local('vanguard-embeddings', emb)
23
+
24
+ elif 'instructor'in model:
25
+
26
+ emb = HuggingFaceInstructEmbeddings(model_name=model,
27
+ query_instruction='Represent the Financial question for retrieving supporting paragraphs: ',
28
+ embed_instruction='Represent the Financial paragraph for retrieval: ')
29
+ return FAISS.load_local('vanguard-embeddings-inst', emb)
30
 
 
31
 
32
+ # vectorstore = load_vectorstore('vanguard-embeddings',sbert_emb)
33
 
34
  _template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
35
  You can assume the question about investing and the investment management industry.
 
113
  type="password",
114
  )
115
 
116
+ embeddings = gr.Radio(choices=list(model_options.keys()),value=list(model_options.keys())[0], label='Choose your Embedding Model')
117
+
118
+ vectorstore = load_vectorstore(model_options[embeddings])
119
+
120
  chatbot = gr.Chatbot()
121
 
122
  with gr.Row():
 
146
  state = gr.State()
147
  agent_state = gr.State()
148
 
149
+
150
  submit.click(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
151
  message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
152