-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebui.py
46 lines (35 loc) · 1.33 KB
/
webui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import logging
import gradio as gr
LOG = logging.getLogger(__name__)
class WebApp(object):
def __init__(self, rds, chain, args):
self.rds = rds
self.chain = chain
self.args = args
def conversation(self, query):
query = query.strip()
docs = self.rds.similarity_search(query, k=3)
LOG.info(query)
LOG.info(docs)
result = self.chain.run(input_documents=docs, question=query)
return result.strip()
def respond(self, message, chat_history):
bot_message = self.conversation(message)
chat_history.append((message, bot_message))
time.sleep(1)
return "", chat_history
def run(self):
with gr.Blocks() as app:
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=1000)
with gr.Row():
with gr.Column(scale=0.85):
msg = gr.Textbox(
show_label=False,
placeholder="Enter your question"
).style(container=False)
with gr.Column(scale=0.15, min_width=0):
clear = gr.Button("Clear")
msg.submit(self.respond, [msg, chatbot], [msg, chatbot])
clear.click(lambda: None, None, chatbot, queue=False)
app.launch(share=self.args.share)