Spaces:
Sleeping
Sleeping
Update chat.py
Browse files
chat.py
CHANGED
|
@@ -123,33 +123,22 @@ def predict(input: str, history: List[Message]):
|
|
| 123 |
|
| 124 |
response = make_completion(input, history)
|
| 125 |
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
# (history[i]["content"], history[i+1]["content"])
|
| 133 |
-
# for i in range(0, len(history)-1, 2)
|
| 134 |
-
# ]
|
| 135 |
-
|
| 136 |
-
# return messages, history
|
| 137 |
|
| 138 |
|
| 139 |
with gr.Blocks() as demo:
|
| 140 |
chatbot = gr.Chatbot(label="CHAT", layout="bubble", likeable=True, show_copy_button=True)
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
gr.ChatInterface(
|
| 147 |
-
fn=predict, chatbot=chatbot,
|
| 148 |
-
title="Chat with information about your insurance policy",
|
| 149 |
-
textbox=gr.Textbox(show_label=True, placeholder="Enter text and press enter"),
|
| 150 |
-
examples=["What is my policy number?", "Are dental expenses covered in my policy?"],
|
| 151 |
-
show_progress="full",
|
| 152 |
-
concurrency_limit=8
|
| 153 |
-
)
|
| 154 |
|
| 155 |
demo.launch(auth=("demouser", os.getenv('PASSWD')))
|
|
|
|
| 123 |
|
| 124 |
response = make_completion(input, history)
|
| 125 |
|
| 126 |
+
history.append({"role": "user", "content": input})
|
| 127 |
+
history.append({"role": "assistant", "content": response})
|
| 128 |
|
| 129 |
+
messages = [
|
| 130 |
+
(history[i]["content"], history[i+1]["content"])
|
| 131 |
+
for i in range(0, len(history)-1, 2)
|
| 132 |
+
]
|
| 133 |
|
| 134 |
+
return messages, history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
with gr.Blocks() as demo:
|
| 138 |
chatbot = gr.Chatbot(label="CHAT", layout="bubble", likeable=True, show_copy_button=True)
|
| 139 |
+
state = gr.State([])
|
| 140 |
+
with gr.Row():
|
| 141 |
+
txt = gr.Textbox(show_label=True, placeholder="Enter text and press enter")
|
| 142 |
+
txt.submit(predict, [txt, state], [chatbot, state])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
demo.launch(auth=("demouser", os.getenv('PASSWD')))
|