Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ def load_vectorstore(model):
|
|
| 33 |
embed_instruction='Represent the Financial paragraph for retrieval: ')
|
| 34 |
return FAISS.load_local('vanguard_embeddings_inst', emb)
|
| 35 |
|
| 36 |
-
#default embeddings
|
| 37 |
vectorstore = load_vectorstore(model_options['all-mpnet-base-v2'])
|
| 38 |
|
| 39 |
def on_value_change(change):
|
|
@@ -73,6 +73,10 @@ def get_chain(vectorstore):
|
|
| 73 |
condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
| 74 |
)
|
| 75 |
return qa_chain
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
class ChatWrapper:
|
|
@@ -102,6 +106,7 @@ block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
|
|
| 102 |
with block:
|
| 103 |
with gr.Row():
|
| 104 |
gr.Markdown("<h3><center>Chat-Your-Data (Investor Education)</center></h3>")
|
|
|
|
| 105 |
|
| 106 |
with gr.Row():
|
| 107 |
embeddings = gr.Radio(choices=model_options_list,value=model_options_list[0], label='Choose your Embedding Model',
|
|
@@ -109,7 +114,7 @@ with block:
|
|
| 109 |
embeddings.change(on_value_change, embeddings)
|
| 110 |
|
| 111 |
vectorstore = load_vectorstore(embeddings.value)
|
| 112 |
-
|
| 113 |
chatbot = gr.Chatbot()
|
| 114 |
|
| 115 |
chat = ChatWrapper()
|
|
@@ -143,10 +148,13 @@ with block:
|
|
| 143 |
agent_state = gr.State()
|
| 144 |
|
| 145 |
|
| 146 |
-
submit.click(chat, inputs=[message, state,
|
| 147 |
-
message.submit(chat, inputs=[message, state,
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
gr.Markdown("")
|
| 152 |
|
|
|
|
| 33 |
embed_instruction='Represent the Financial paragraph for retrieval: ')
|
| 34 |
return FAISS.load_local('vanguard_embeddings_inst', emb)
|
| 35 |
|
| 36 |
+
#default embeddings and store
|
| 37 |
vectorstore = load_vectorstore(model_options['all-mpnet-base-v2'])
|
| 38 |
|
| 39 |
def on_value_change(change):
|
|
|
|
| 73 |
condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
| 74 |
)
|
| 75 |
return qa_chain
|
| 76 |
+
|
| 77 |
+
def load_chain():
|
| 78 |
+
chain = get_chain(vectorstore)
|
| 79 |
+
return chain
|
| 80 |
|
| 81 |
|
| 82 |
class ChatWrapper:
|
|
|
|
| 106 |
with block:
|
| 107 |
with gr.Row():
|
| 108 |
gr.Markdown("<h3><center>Chat-Your-Data (Investor Education)</center></h3>")
|
| 109 |
+
enbed_but = gr.Button(value='Load QA Chain')
|
| 110 |
|
| 111 |
with gr.Row():
|
| 112 |
embeddings = gr.Radio(choices=model_options_list,value=model_options_list[0], label='Choose your Embedding Model',
|
|
|
|
| 114 |
embeddings.change(on_value_change, embeddings)
|
| 115 |
|
| 116 |
vectorstore = load_vectorstore(embeddings.value)
|
| 117 |
+
|
| 118 |
chatbot = gr.Chatbot()
|
| 119 |
|
| 120 |
chat = ChatWrapper()
|
|
|
|
| 148 |
agent_state = gr.State()
|
| 149 |
|
| 150 |
|
| 151 |
+
submit.click(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
|
| 152 |
+
message.submit(chat, inputs=[message, state, agent_state], outputs=[chatbot, state])
|
| 153 |
|
| 154 |
+
embed_but.change(
|
| 155 |
+
load_chain,
|
| 156 |
+
outputs=[agent_state],
|
| 157 |
+
)
|
| 158 |
|
| 159 |
gr.Markdown("")
|
| 160 |
|