pgurazada1 commited on
Commit
fa5b83b
·
verified ·
1 Parent(s): 0fa1cc4

Update chat.py

Browse files
Files changed (1) hide show
  1. chat.py +15 -12
chat.py CHANGED
@@ -115,7 +115,7 @@ def make_completion(input:str, history: List[Message]) -> Optional[str]:
115
  return prediction
116
 
117
 
118
- def predict(input, history):
119
 
120
  """
121
  Predict the response of the chatbot and complete a running list of chat history.
@@ -123,27 +123,30 @@ def predict(input, history):
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
  gr.ChatInterface(
145
  fn=predict, chatbot=chatbot,
146
  title="Chat with information about your insurance policy",
 
147
  examples=["What is my policy number?", "Are dental expenses covered in my policy?"],
148
  show_progress="full",
149
  concurrency_limit=8
 
115
  return prediction
116
 
117
 
118
+ def predict(input: str, history: List[Message]):
119
 
120
  """
121
  Predict the response of the chatbot and complete a running list of chat history.
 
123
 
124
  response = make_completion(input, history)
125
 
126
+ return response
 
127
 
128
+ # history.append({"role": "user", "content": input})
129
+ # history.append({"role": "assistant", "content": response})
 
 
130
 
131
+ # messages = [
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
+ # state = gr.State([])
142
+ # with gr.Row():
143
+ # txt = gr.Textbox(show_label=True, placeholder="Enter text and press enter")
144
+ # txt.submit(predict, [txt, state], [chatbot, state])
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