Mr-Geo commited on
Commit
409b716
·
verified ·
1 Parent(s): 4959f0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -255,17 +255,17 @@ if __name__ == "__main__":
255
  gr.Markdown("# Website Chat Assistant")
256
  gr.Markdown("Ask questions about the website.")
257
 
258
- chatbot = gr.Chatbot(height=600)
259
  msg = gr.Textbox(placeholder="Ask a question...", label="Your question")
260
  clear = gr.Button("Clear")
261
 
262
  def user(user_message, history):
263
- return "", history + [[user_message, None]]
264
 
265
  def bot(history):
266
- if history and history[-1][1] is None:
267
- for response in chat_response(history[-1][0], history[:-1]):
268
- history[-1][1] = response
269
  yield history
270
 
271
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
@@ -274,10 +274,10 @@ if __name__ == "__main__":
274
 
275
  clear.click(lambda: None, None, chatbot, queue=False)
276
 
277
- # Launch with minimal configuration
278
  demo.queue()
279
  demo.launch(
280
- server_name="127.0.0.1",
281
  server_port=7860,
282
  share=False
283
  )
 
255
  gr.Markdown("# Website Chat Assistant")
256
  gr.Markdown("Ask questions about the website.")
257
 
258
+ chatbot = gr.Chatbot(height=600, type='messages')
259
  msg = gr.Textbox(placeholder="Ask a question...", label="Your question")
260
  clear = gr.Button("Clear")
261
 
262
  def user(user_message, history):
263
+ return "", history + [{"role": "user", "content": user_message}]
264
 
265
  def bot(history):
266
+ if history and history[-1]["role"] == "user":
267
+ for response in chat_response(history[-1]["content"], history[:-1]):
268
+ history.append({"role": "assistant", "content": response})
269
  yield history
270
 
271
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
274
 
275
  clear.click(lambda: None, None, chatbot, queue=False)
276
 
277
+ # Launch with configuration for Hugging Face Spaces
278
  demo.queue()
279
  demo.launch(
280
+ server_name="0.0.0.0",
281
  server_port=7860,
282
  share=False
283
  )