Update app.py
Browse files
app.py
CHANGED
@@ -76,7 +76,6 @@ def get_chain(vectorstore):
|
|
76 |
|
77 |
|
78 |
class ChatWrapper:
|
79 |
-
global chain
|
80 |
|
81 |
def __init__(self):
|
82 |
self.lock = Lock()
|
@@ -88,7 +87,7 @@ class ChatWrapper:
|
|
88 |
try:
|
89 |
history = history or []
|
90 |
# Set OpenAI key
|
91 |
-
chain = get_chain(vectorstore)
|
92 |
# Run chain and append input.
|
93 |
output = chain({"question": inp, "chat_history": history})["answer"]
|
94 |
history.append((inp, output))
|
@@ -110,7 +109,7 @@ with block:
|
|
110 |
embeddings.change(on_value_change, embeddings)
|
111 |
|
112 |
vectorstore = load_vectorstore(embeddings.value)
|
113 |
-
|
114 |
chatbot = gr.Chatbot()
|
115 |
|
116 |
chat = ChatWrapper()
|
@@ -144,8 +143,8 @@ with block:
|
|
144 |
agent_state = gr.State()
|
145 |
|
146 |
|
147 |
-
submit.click(chat, inputs=[message, state,
|
148 |
-
message.submit(chat, inputs=[message, state,
|
149 |
|
150 |
# agent_state = chain
|
151 |
|
|
|
76 |
|
77 |
|
78 |
class ChatWrapper:
|
|
|
79 |
|
80 |
def __init__(self):
|
81 |
self.lock = Lock()
|
|
|
87 |
try:
|
88 |
history = history or []
|
89 |
# Set OpenAI key
|
90 |
+
# chain = get_chain(vectorstore)
|
91 |
# Run chain and append input.
|
92 |
output = chain({"question": inp, "chat_history": history})["answer"]
|
93 |
history.append((inp, output))
|
|
|
109 |
embeddings.change(on_value_change, embeddings)
|
110 |
|
111 |
vectorstore = load_vectorstore(embeddings.value)
|
112 |
+
chain = get_chain(vectorstore)
|
113 |
chatbot = gr.Chatbot()
|
114 |
|
115 |
chat = ChatWrapper()
|
|
|
143 |
agent_state = gr.State()
|
144 |
|
145 |
|
146 |
+
submit.click(chat, inputs=[message, state, chain], outputs=[chatbot, state])
|
147 |
+
message.submit(chat, inputs=[message, state, chain], outputs=[chatbot, state])
|
148 |
|
149 |
# agent_state = chain
|
150 |
|